update pagination if page param changes
This commit is contained in:
parent
32988bb7ca
commit
41edd8317c
1 changed files with 8 additions and 1 deletions
|
@ -20,7 +20,8 @@ function Paginate(props: Props) {
|
|||
const { search } = location;
|
||||
const [textValue, setTextValue] = React.useState('');
|
||||
const urlParams = new URLSearchParams(search);
|
||||
const initialPage = disableHistory ? 1 : Number(urlParams.get(PAGINATE_PARAM)) || 1;
|
||||
const urlParamPage = Number(urlParams.get(PAGINATE_PARAM));
|
||||
const initialPage = disableHistory ? 1 : urlParamPage || 1;
|
||||
const [currentPage, setCurrentPage] = React.useState(initialPage);
|
||||
const isMobile = useIsMobile();
|
||||
|
||||
|
@ -47,6 +48,12 @@ function Paginate(props: Props) {
|
|||
}
|
||||
}
|
||||
|
||||
React.useEffect(() => {
|
||||
if (urlParamPage) {
|
||||
setCurrentPage(urlParamPage);
|
||||
}
|
||||
}, [urlParamPage, setCurrentPage]);
|
||||
|
||||
return (
|
||||
// Hide the paginate controls if we are loading or there is only one page
|
||||
// It should still be rendered to trigger the onPageChange callback
|
||||
|
|
Loading…
Reference in a new issue