Skip to content

Commit

Permalink
Fix table API requests firing twice upon changing page
Browse files Browse the repository at this point in the history
  • Loading branch information
leSamo committed Mar 1, 2024
1 parent ec79ca0 commit bf870af
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Helpers/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,13 @@ export const useUrlBoundParams = ({
const dispatch = useDispatch();

const [getUrlParams, setUrlParams] = useUrlParams(allowedParams);
const [isFirstLoad, setFirstLoad] = useState(true);

// if a user clicks on the currently loaded page in the navbar,
// page would not refresh, but the URL would clear; this useEffect
// solves this inconsistent state
useEffect(() => {
if (window.location.search === '') {
if (!isFirstLoad && window.location.search === '') {
apply({ ...initialParams });
}
}, [window.location.search]);
Expand All @@ -142,6 +146,7 @@ export const useUrlBoundParams = ({
const initialUrlParams = getUrlParams();

apply({ ...initialParams, ...initialUrlParams });
setFirstLoad(false);
}, []);

const apply = (newParams, isReset = false) => {
Expand Down

0 comments on commit bf870af

Please sign in to comment.