-
Notifications
You must be signed in to change notification settings - Fork 301
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
[BUG]: @toss/react default values setting of useStorageState #421
Comments
It works to add code to this line rather than add code to the line you mentioned. const getValue = useCallback(<T>() => {
const data = storage.get(key);
if (data == null) {
storage.set(key, JSON.stringify(defaultValue)); // add this line
return defaultValue;
}
try {
const result = JSON.parse(data);
// ...
// ... But I think we should avoid setting the value inside the getValue function (because it's a side effect) I think we need a logic to set defaultValue to storage right after component mount, we need to useEffect because this is synchronizing with external system. |
1 task
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Package Scope
Package name: @toss/react
Describe the bug
If a value is initialized through
defaultValue
, the value is not set in thesession storage
.Expected behavior
Even if the set function is not executed, if the value is initialized through
defaultValue
, the value must be set in thesession storage.
To Reproduce
Possible Solution
Additional context
The text was updated successfully, but these errors were encountered: