When I add a recipe, local storage updates, but when I edit or delete one, it doesn’t (unless I also add a new recipe to write the whole state back to storage).
And I think the problem is something to do with the way componentDidUpdate works…maybe a child updating isn’t enough to trigger a full re-render that the componentDidUpdate method recognises?
A Melbourne camper spotted the issue in our Slack channel.
I was conditionally checking against the length of the recipes array in state. When I removed that condition and just wrote the state to storage in every update, it worked.
Probably a few more CPU cycles than necessary…but it’ll do
You could wrap it into a throttling / debounce function.
That’s a common pattern when writing in storage.
(you’ll find it probably even on the Redux documentation about subscribing store changes to localStorage).
Not that you really need it for a recipe app… but it’s good to know imho