-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a way to clear localStorage in useLocalStorage #229
Comments
Here is a demo of the issue I'm having with clearing the local storage: it comes back after a page refresh. |
feat(useLocalStorage): add remove method. (#229)
@streamich Hi, considering the api for |
# [15.0.0](v14.3.0...v15.0.0) (2020-05-16) * v15 release ([0f82ba6](0f82ba6)) ### Bug Fixes * 🐛 better serialization handling in useLocalStorage hook ([68fb835](68fb835)) * 🐛 correctly test if env is browser in useMeasure ([9ae494f](9ae494f)) * 🐛 make useMeasure work on server ([2daf769](2daf769)) * 🐛 remove set dependencies in useSet hook ([90ba9d0](90ba9d0)) * 🐛 revert useMeasure defaults to zeros ([dc92b64](dc92b64)) * remove console log 🤓 ([f17c8a0](f17c8a0)) * **useLocalStorage:** using undefined for empty value instead of null ([1620e01](1620e01)) * use latest set object in useSet "has" method ([41f9452](41f9452)) ### Features * 🎸 add useScratch() sensor hook ([58db2f9](58db2f9)) * 🎸 catch up with v14 ([be69035](be69035)) * 🎸 improve implementation of useMeasure() hook ([a164843](a164843)) * 🎸 improve implementation of useMeasure() hook ([4d88240](4d88240)) * 🎸 mock useMeasure() hook on server and w/o ResizeObserver ([866f3d7](866f3d7)) * 🎸 mock useMeasure() hook on server and w/o ResizeObserver ([2bbc73a](2bbc73a)) * 🎸 remove resize-observer-polyfill from useMeasure ([2a13fba](2a13fba)) * 🎸 remove resize-observer-polyfill from useMeasure ([bf11131](bf11131)) * Dependencies inference for useCustomCompareEffect ([477c164](477c164)) * improve useAsyncFn and useAsync typings ([85967e2](85967e2)) * keep previous state in useAsyncFn ([54ac91b](54ac91b)) * use useReducer in useUpdate hook, instead of useState + useCallback ([6575b14](6575b14)) * **useLocalStorage:** add remove feature. ([#229](#229)) ([587de16](587de16)) ### BREAKING CHANGES * implementation of useMeasure and useLocalStorage changed * resize-observer-polyfill package is not used with useMeasure() hook anymore. * useMeasure() now defaults all values to -1, if they were not set and internal implementation heavily refactored. * useAsyncFn now keeps hold of old result/error when called multiple times * resize-observer-polyfill package is not used with useMeasure() hook anymore. * useMeasure() now defaults all values to -1, if they were not set and internal implementation heavily refactored.
Shipped in |
I did the trick for session storage too. See #2314 |
I use
useLocalStorage
a lot, and it could use a cleanup story in some cases.Maybe as a third tuple member, have a function to call to clear the item, that respects the side-effects lifetime, as I found that simply calling
localStorage.removeItem(key)
can create a race condition with the hook recreating the value from memory.Example:
The text was updated successfully, but these errors were encountered: