Skip to content

Commit

Permalink
🐛 [#546] Fix cascade of requests firing
Browse files Browse the repository at this point in the history
Hook dependencies operate on the identity, and the identity of
the selectedProducts changes every time on each render, while the
contents stay the same.

JSON.stringify is the recommended approach to mitigate using non-primivites
in hook dependency arrays.

Note that the caching masked the issue partially - it caused the
request cascade to stop, but the problem still showed with multi-
product appointments.

Backport-of: #569
  • Loading branch information
sergei-maertens committed Oct 23, 2023
1 parent a2193e6 commit 78b1b76
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/components/appointments/ProductSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ const ProductSelect = ({name, selectedProducts}) => {
const {value} = getFieldProps(name);
const getOptions = useCallback(
async () => await getProducts(baseUrl, selectedProducts, value),
[baseUrl, selectedProducts, value]
// eslint-disable-next-line react-hooks/exhaustive-deps
[baseUrl, JSON.stringify(selectedProducts), value]
);
return (
<AsyncSelectField
Expand Down

0 comments on commit 78b1b76

Please sign in to comment.