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

Unable to update a value once you have set it once #1

Open
andrewsnowden opened this issue Oct 5, 2017 · 4 comments
Open

Unable to update a value once you have set it once #1

andrewsnowden opened this issue Oct 5, 2017 · 4 comments
Labels

Comments

@andrewsnowden
Copy link

Hey,

So we ported some of this to use on Android phones but this line seems to be wrong:

const nextTree = { [key]: JSON.parse(value), ...tree }

If you already have the key in your existing tree, then it will just overwrite your new value. So you can write a value once, but then you can never update it again.

Suggestion is to use something like

const nextTree = Object.assign({}, tree, {key: JSON.parse(value)})

Or even a simple assign if you don't mind it being mutated.

@jsdario
Copy link
Member

jsdario commented Oct 5, 2017

Sorry, this was a major mistake. We were using a local copy of this file that has the correct expressions.
In ES6/7 syntax it would be read as:

const nextTree = { ...tree, [key]: value }

I'll create a PR and submit for you to review, if it is alright.
Thanks a lot!

@jsdario
Copy link
Member

jsdario commented Oct 5, 2017

I directly updated it into master, you can check the changes here
I also published it to npm.

@jsdario jsdario added the bug label Oct 5, 2017
@HaswinVidanage
Copy link

@jsdario is this issue fixed?

@jsdario
Copy link
Member

jsdario commented Mar 12, 2018

Yes, but this project has other issues, depending on the version of redux-persist that you are using. In v4 at least, some parts of the state can be overwritten due to racing conditions on the use of redux-persist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants