When building web applications I often use this method to add local storage caching of my state.
Suppose we're starting with :
const [state, d...
For further actions, you may consider blocking this person and/or reporting abuse
Very weird stuff ! It's not at all recommended to do that.
It's recommended to change the state key when changing the structure of the store (e.g. my-state-1, my-state-2)
This technique as is, requires the state to be serializable, to handle special cases you would need to add custom parsing and
stringifyingfor non-serializable variables or simply ignore them when reading and writing to the the cache.Thanks for taking the time to write that !
The main reason I didn't go into it, is to keep the code under 5 lines 😅
I wanted the reader to quickly understand the idea of using HOFs with the reducer and build on it and experiment themselves.
Now they can also read/use this hook 👌