Instead of using storedValue as a dependency within the setValue callback in createStorageHook.ts we are getting the current stored value from setStoredValue directly. This stops the setValue callback from unnecessarily being recreated every time the storedValue changes.
Description
Instead of using
storedValue
as a dependency within thesetValue
callback increateStorageHook.ts
we are getting the current stored value fromsetStoredValue
directly. This stops thesetValue
callback from unnecessarily being recreated every time the storedValue changes.Related Issue
https://github.com/antonioru/beautiful-react-hooks/issues/395
Motivation and Context
I was getting an infinite loop when
setValue
was used as a dependency on a useEffect where the effect was callingsetValue
.https://github.com/antonioru/beautiful-react-hooks/issues/395
How Has This Been Tested?
Added additional unit tests.
Screenshots (if appropriate):