Try wrapping your hydrate function into a useCallback hook, also use the callback in the setState function not the state it self so you don't have to set a dependency to it, the same goes for the Errors state object
Ironically this is exactly what i ended up doing. Thanks for sharing though, as someone who is new to hooks, its very helpful to learn about useCallback(). i think now i will refactor much of my code to take advantage of this feature.
Try wrapping your hydrate function into a
useCallback
hook, also use the callback in thesetState
function not the state it self so you don't have to set a dependency to it, the same goes for the Errors state objectAfter that add the
hydrate
to youruseEffect()
dependency array,As the
hydrate
function has no dependencies it will be initialised only once. So your effect should be executed only once.Please try and see if this helps you
Ironically this is exactly what i ended up doing. Thanks for sharing though, as someone who is new to hooks, its very helpful to learn about
useCallback()
. i think now i will refactor much of my code to take advantage of this feature.useCallback
anduseMemo
are very useful to know. I think I'll post something on this subject as it's good to know when and where to use them