Skip to content
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

useLocalStorage doesn't not remove key on setValue(undefined) #2539

Closed
billsbooth opened this issue Feb 8, 2024 · 1 comment
Closed

useLocalStorage doesn't not remove key on setValue(undefined) #2539

billsbooth opened this issue Feb 8, 2024 · 1 comment

Comments

@billsbooth
Copy link

What is the current behavior?
Set value to undefined does not remove the key from local storage.
What is the expected behavior?
Delete the key!
A little about versions:

  • OS: MacOS 14.2 (23C64)
  • Browser (vendor and version): Version 121.0.6167.139 (Official Build) (arm64)
  • React: "react": "18.2.0",
  • react-use: "react-use": "^17.4.0",
  • _Did this worked in the previous package version? Not sure.
const [v, setV] = useLocalStorage<string>("__test__");
...
<Flex className="relative h-screen w-screen flex-col items-center justify-center overflow-hidden">
      <h1>{v}</h1>
      <button onClick={() => {setV('foo')} }>Set</button>
      <button onClick={() => {setV(undefined)}}>Unset</button>
</Flex>
...
@billsbooth
Copy link
Author

Lol, I was using react-use, instead of reactuse. They have an additional remove() function. This is kinda frustrating.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant