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.
  • Loading branch information
sergei-maertens committed Oct 19, 2023
1 parent b3b2a21 commit c8c9684
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/components/appointments/fields/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 c8c9684

Please sign in to comment.