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

useLocalStorageValue yields undefined on firstRender if initializeWithValue not set #1002

Closed
Evalon opened this issue Nov 3, 2022 · 2 comments
Labels
🪲 bug Something isn't working released

Comments

@Evalon
Copy link

Evalon commented Nov 3, 2022

What is the current behavior?

useLocalStorageValue yields undefined on first render if initializeWithValue not set to true and on second render yield actual value from localStorage.

https://codesandbox.io/s/wispy-forest-qmrlzn?file=/src/App.tsx

What is the expected behavior?

initializeWithValue: true should be default behavior based on documentation and previous behaviour.

Environment Details

  • _@react-hookz/web version: 17.0
  • _react version: 18.2
  • _react-dom version: 18.2
  • _typescript version: 4.8.4
  • _OS: macos
  • _Browser: chrome
  • _Did this work in previous versions? yes
@ArttuOll ArttuOll added the 🪲 bug Something isn't working label Nov 4, 2022
@ArttuOll
Copy link
Contributor

ArttuOll commented Nov 4, 2022

Thanks for the bug report!

I managed to repeat this. Indeed, it seems that the default value of initializeWithValue is false even though in the code (and in the docs) it definitely looks like it should be true.

I'm looking into this.

ArttuOll added a commit that referenced this issue Nov 4, 2022
…nstead of true

The bug was caused by an accidental reference to a variable with the raw options provided by props
instead of the variable with the props-provided options and default options merged.

fix #1002
ArttuOll added a commit that referenced this issue Nov 4, 2022
The bug was caused by accidental references to a variable with the raw options provided by props
instead of the variable with the props-provided options and default options merged.

fix #1002
ArttuOll added a commit that referenced this issue Nov 4, 2022
The bug was caused by accidental references to a variable with the raw options provided by props
instead of the variable with the props-provided options and default options merged.

fix #1002
ArttuOll added a commit that referenced this issue Nov 4, 2022
This option was previously true by default, which is in conflict with this library's goal of
supporting SSR out of the box. Also the documentation and the tests seem to presume that
initializeWithValue is false by default. This is not a breaking change since due to a bug (#1002)
initializeWithValue was effectively false by default already.

re #1002
@xobotyi xobotyi closed this as completed in 1f730d6 Nov 5, 2022
github-actions bot pushed a commit that referenced this issue Nov 5, 2022
## [17.0.1](v17.0.0...v17.0.1) (2022-11-05)

### Bug Fixes

* **useStorageValue:** respect `initializeWithValue` default, fix docs and tests ([#1003](#1003)) ([1f730d6](1f730d6)), closes [#1002](#1002)
@xobotyi
Copy link
Contributor

xobotyi commented Nov 5, 2022

🎉 This issue has been resolved in version 17.0.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🪲 bug Something isn't working released
Development

No branches or pull requests

3 participants