Skip to content

Commit

Permalink
fix: fix filter form syncing issues from url
Browse files Browse the repository at this point in the history
  • Loading branch information
mainawycliffe authored and moshloop committed Jun 6, 2024
1 parent b1f8e78 commit 2167f19
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/components/Forms/FormikFilterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,17 @@ function FormikChangesListener({
paramsToReset.forEach((param) => searchParams.delete(param));
setSearchParams(searchParams);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [values]);
}, [values, setFieldValue]);

// reset form values, if the query params change
useEffect(() => {
filterFields.forEach((field) => {
const value = searchParams.get(field);
const defaultValue = defaultFieldValues?.[field] ?? undefined;
if (!value) {
if (defaultValue) {
setFieldValue(field, defaultValue);
} else {
setFieldValue(field, undefined);
}
}
setFieldValue(field, value ?? defaultValue);
}, []);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [searchParams]);
}, [defaultFieldValues, filterFields, searchParams]);

// eslint-disable-next-line react/jsx-no-useless-fragment
return <>{children}</>;
Expand Down

0 comments on commit 2167f19

Please sign in to comment.