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 allow to store value without getInitialValueInEffect set to true #5796

Closed
1 of 2 tasks
lgaspari opened this issue Feb 20, 2024 · 2 comments
Closed
1 of 2 tasks
Labels
Fixed patch Completed issues that will be published with next patch (1.0.X)

Comments

@lgaspari
Copy link
Contributor

Dependencies check up

  • I have verified that I use latest version of all @mantine/* packages

What version of @mantine/* packages do you have in package.json?

7.5.3

What package has an issue?

@mantine/hooks

What framework do you use?

Vite

In which browsers you can reproduce the issue?

Chrome

Describe the bug

Hello folks,

Looking at the useLocalStorage hook, even though there's a useEffect() for saving the value on storage when value is undefined but defaultValue is not (see here), it never runs because value is always populated with defaultValue (see here as well).

I'm thinking that maybe it has been done this way for SSR because they need the Local Storage available before running, therefore a side-effect would be ideal, but if we are not using SSR and need the value to persist on stage on mount, I have to set getInitialValueInEffect to true. Is this actually the case? If so, that side-effect seems redundant.

As a side question, is it possible that there are no tests for this hook?

Thanks a lot!

If possible, include a link to a codesandbox with a minimal reproduction

https://codesandbox.io/p/sandbox/mantine-react-template-forked-wdsz8j

Possible fix

We could remove the defaultValue from this line but that would certainly break other things. Otherwise, the useEffect() could be removed if redundant.

Self-service

  • I would be willing to implement a fix for this issue
rtivital added a commit that referenced this issue Feb 26, 2024
…rsistence if `getInitialValueInEffect` is set (#5796)
@rtivital rtivital added the Fixed patch Completed issues that will be published with next patch (1.0.X) label Feb 26, 2024
@rtivital
Copy link
Member

Fixed in 7.6.1

@lgaspari
Copy link
Contributor Author

Fixed in 7.6.1

It works like a charm, thank you 👍🏼

I was wondering if you were able to take a look at the useEffect() I mentioned above that doesn't actually run (here). I believe it's redundant giving the fact that there's always a value but I could totally create a separate issue for that, lmk!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed patch Completed issues that will be published with next patch (1.0.X)
Projects
None yet
Development

No branches or pull requests

2 participants