Skip to content

Commit

Permalink
fix: keep ref to debounced func
Browse files Browse the repository at this point in the history
  • Loading branch information
swouf committed May 27, 2024
1 parent 3149a44 commit 161ec85
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"@cypress/code-coverage": "3.12.39",
"@trivago/prettier-plugin-sort-imports": "4.3.0",
"@types/i18n": "0.13.12",
"@types/lodash.debounce": "^4",
"@types/lodash.debounce": "4.0.9",
"@types/lodash.isequal": "^4",
"@types/lodash.sortby": "^4",
"@types/lodash.uniqby": "^4",
Expand Down
3 changes: 2 additions & 1 deletion src/modules/context/UserAnswersContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const UserAnswersProvider: FC<{
useState<UserAnswerAppData[]>();

const cachePayload = useRef<UserAnswer>();
const debouncedPatch = useRef<ReturnType<typeof debounce>>();
const { mutate: postAppData } = mutations.usePostAppData();
const { mutate: patchAppData } = mutations.usePatchAppData();
const { mutate: deleteAppData } = mutations.useDeleteAppData();
Expand Down Expand Up @@ -91,7 +92,7 @@ export const UserAnswersProvider: FC<{
};
if (userAnswerAppData?.id) {
cachePayload.current = payloadData;
debounce(
debouncedPatch.current = debounce(
() =>
patchAppData({
...userAnswerAppData,
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3932,7 +3932,7 @@ __metadata:
languageName: node
linkType: hard

"@types/lodash.debounce@npm:^4":
"@types/lodash.debounce@npm:4.0.9":
version: 4.0.9
resolution: "@types/lodash.debounce@npm:4.0.9"
dependencies:
Expand Down Expand Up @@ -8228,7 +8228,7 @@ __metadata:
"@tanstack/react-query-devtools": "npm:4.36.1"
"@trivago/prettier-plugin-sort-imports": "npm:4.3.0"
"@types/i18n": "npm:0.13.12"
"@types/lodash.debounce": "npm:^4"
"@types/lodash.debounce": "npm:4.0.9"
"@types/lodash.isequal": "npm:^4"
"@types/lodash.sortby": "npm:^4"
"@types/lodash.uniqby": "npm:^4"
Expand Down

0 comments on commit 161ec85

Please sign in to comment.