useLocalStorage
doesn't allow to store value without getInitialValueInEffect
set to true
#5796
Closed
1 of 2 tasks
Labels
Fixed patch
Completed issues that will be published with next patch (1.0.X)
Dependencies check up
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 auseEffect()
for saving the value on storage whenvalue
isundefined
butdefaultValue
is not (see here), it never runs becausevalue
is always populated withdefaultValue
(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
totrue
. 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, theuseEffect()
could be removed if redundant.Self-service
The text was updated successfully, but these errors were encountered: