From c81f50e3df9bbb382a53f3300246731d456811b4 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi <256895@studenti.unimore.it> Date: Thu, 29 Apr 2021 05:03:34 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20hooks=20dependencies?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/frontend/src/hooks/useArrayState.js | 18 ++++++++++++++---- code/frontend/src/hooks/useData.js | 4 ++-- .../frontend/src/hooks/useLocalStorageState.js | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/code/frontend/src/hooks/useArrayState.js b/code/frontend/src/hooks/useArrayState.js index a0d312e..d8b895a 100644 --- a/code/frontend/src/hooks/useArrayState.js +++ b/code/frontend/src/hooks/useArrayState.js @@ -10,10 +10,10 @@ export default function useArrayState(def) { oldArray => [...oldArray, newSingle] ) }, - [value, setValue] + [] ) - const removeValue = useCallback( + const spliceValue = useCallback( position => { setValue( oldArray => { @@ -22,8 +22,18 @@ export default function useArrayState(def) { return oldArray } ) - } + }, + [] ) - return {value, setValue, appendValue, removeValue} + const removeValue = useCallback( + remValue => { + setValue( + oldArray => oldArray.filter(item => item !== remValue) + ) + }, + [] + ) + + return {value, setValue, appendValue, spliceValue, removeValue} } \ No newline at end of file diff --git a/code/frontend/src/hooks/useData.js b/code/frontend/src/hooks/useData.js index a729653..d440b65 100644 --- a/code/frontend/src/hooks/useData.js +++ b/code/frontend/src/hooks/useData.js @@ -35,7 +35,7 @@ export default function useData(fetchData, method, path, body, init) { setLoading(false) } }, - [fetchData, method, path, body, init, setData, setError, setLoading] + [fetchData, method, path, body, init] ) /** @@ -51,7 +51,7 @@ export default function useData(fetchData, method, path, body, init) { await load() }, - [load, setData, setError] + [load] ) useEffect( diff --git a/code/frontend/src/hooks/useLocalStorageState.js b/code/frontend/src/hooks/useLocalStorageState.js index 4734666..f53c868 100644 --- a/code/frontend/src/hooks/useLocalStorageState.js +++ b/code/frontend/src/hooks/useLocalStorageState.js @@ -54,7 +54,7 @@ export default function useLocalStorageState(key, def) { setValue(value) save(value) }, - [setValue, save] + [save] ) return [value, setAndSave]