-
// working good
import React from 'react';
import { connectPagination } from 'react-instantsearch-dom';
const Pagination = ({
currentRefinement,
nbPages,
refine,
}: {
currentRefinement: number;
nbPages: number;
refine: (value: number) => void;
}) => {
return (
<div className="flex justify-between">
{/* Should it be> 0 ?*/}
{currentRefinement > 1 && (
<button
onClick={() => refine(currentRefinement - 1)}
className="relative inline-flex items-center px-4 py-2 border border-gray-300 text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50"
>
Prev
</button>
)}
{nbPages > currentRefinement && (
<button
onClick={() => refine(currentRefinement + 1)}
className="ml-3 relative inline-flex items-center px-4 py-2 border border-gray-300 text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50"
>
Next
</button>
)}
</div>
);
};
const CustomPagination = connectPagination(Pagination);
export default CustomPagination; // same result
<CustomPagination defaultRefinement={0} />
<CustomPagination defaultRefinement={1} /> In light of searchstate etc., page: 0 seems to behave as currentRefinement: 1 in this widget. Is my understanding correct? |
Beta Was this translation helpful? Give feedback.
Answered by
Haroenv
Feb 7, 2022
Replies: 0 comments 2 replies
-
The defaultRefinement and searchState is 1-based, as that's what users would be expecting to see. As a refinement of 0 would not be possible, the connector doesn't deal with that as expected, and still shows the first page. This means that your component is behaving exactly as expected, but you should use defaultRefinement={1}, not 0 |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
nino-cast
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The defaultRefinement and searchState is 1-based, as that's what users would be expecting to see. As a refinement of 0 would not be possible, the connector doesn't deal with that as expected, and still shows the first page. This means that your component is behaving exactly as expected, but you should use defaultRefinement={1}, not 0