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

useLocalStorageReducer state by default is undefined #8

Closed
AdamSalma opened this issue Sep 12, 2019 · 2 comments
Closed

useLocalStorageReducer state by default is undefined #8

AdamSalma opened this issue Sep 12, 2019 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@AdamSalma
Copy link

   const MyComponent = () => {
     const [state, dispatch, writeError] = useLocalStorageReducer(
        key,
        reducer,
       {
            count: 1
       }
     );

     console.log(state)
     return null
  }

This initially logs state as undefined a few times until dispatch is called, which is causing unexpected behaviour with my code.

Is this intentional?

@soyguijarro
Copy link
Owner

Hi @AdamSalma, thanks for reporting!

Let me see if I'm understanding this: the key in your storage has no value and you're getting undefined a few times before getting { count: 1}, is that right? That does sound like a bug. I'm working on a full rewrite of the library, so I'll keep this in mind so that it's fixed in the new version.

@soyguijarro soyguijarro added the bug Something isn't working label Feb 27, 2020
@soyguijarro soyguijarro self-assigned this Feb 27, 2020
@soyguijarro
Copy link
Owner

soyguijarro commented Mar 4, 2020

@AdamSalma This should be fixed in version 4.0.0 that I've just published, so I'm closing this issue. Feel free to reopen if it keeps happening.

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

No branches or pull requests

2 participants