1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-22 04:54:18 +00:00

🐛 Fix hooks dependencies

This commit is contained in:
Stefano Pigozzi 2021-04-29 05:03:34 +02:00
parent 344544da52
commit c81f50e3df
Signed by untrusted user who does not match committer: steffo
GPG key ID: 6965406171929D01
3 changed files with 17 additions and 7 deletions

View file

@ -10,10 +10,10 @@ export default function useArrayState(def) {
oldArray => [...oldArray, newSingle] oldArray => [...oldArray, newSingle]
) )
}, },
[value, setValue] []
) )
const removeValue = useCallback( const spliceValue = useCallback(
position => { position => {
setValue( setValue(
oldArray => { oldArray => {
@ -22,8 +22,18 @@ export default function useArrayState(def) {
return oldArray return oldArray
} }
) )
} },
[]
) )
return {value, setValue, appendValue, removeValue} const removeValue = useCallback(
remValue => {
setValue(
oldArray => oldArray.filter(item => item !== remValue)
)
},
[]
)
return {value, setValue, appendValue, spliceValue, removeValue}
} }

View file

@ -35,7 +35,7 @@ export default function useData(fetchData, method, path, body, init) {
setLoading(false) 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() await load()
}, },
[load, setData, setError] [load]
) )
useEffect( useEffect(

View file

@ -54,7 +54,7 @@ export default function useLocalStorageState(key, def) {
setValue(value) setValue(value)
save(value) save(value)
}, },
[setValue, save] [save]
) )
return [value, setAndSave] return [value, setAndSave]