antonioru / beautiful-react-hooks

🔥 A collection of beautiful and (hopefully) useful React hooks to speed-up your components and hooks development 🔥
https://antonioru.github.io/beautiful-react-hooks/
MIT License
8.17k stars 577 forks source link

🐛 useLocalStorage no longer returns a new setValue function every time setValue is called #400

Closed jaalru closed 1 year ago

jaalru commented 1 year ago

Description

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.

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 calling setValue.

https://github.com/antonioru/beautiful-react-hooks/issues/395

How Has This Been Tested?

Added additional unit tests.

Screenshots (if appropriate):