usehooks
usehooks copied to clipboard
Add useMemo call to useLocalStorage so that the value returned only changes if store actually changes.
At the moment if a component that uses useLocalStorage
rerenders then useLocalStorage
will call JSON.parse(store)
as a result of the rerender. The value of store
won't have changed, but the new call to JSON.parse
will mean that a new value is returned with identical contents to the old value. Any hooks then using that value in their deps array will then have to be run again, even though the actual data is the same.
I've updated useLocalStorage so that it uses useMemo
to avoid repeated calls to JSON.parse
with the same store value.