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

Removal of property does not have any effect #1062

Open
gultyayev opened this issue Apr 14, 2023 · 1 comment
Open

Removal of property does not have any effect #1062

gultyayev opened this issue Apr 14, 2023 · 1 comment

Comments

@gultyayev
Copy link

Is this a regression?

No

Description

I have a very simple store which consists of key-value pairs [key: string]: true.
I try to run update and delete one of the keys from the store. However, the store produces no changes as evident from Redux devtools and the observed state in the UI.

I have tried it with and without Immer.

this.store.update(state => {
  const newState = { ...state }; // { a: true, b: true }

  delete newState[a]

  return newState;
}

As a result newState is an object with one property b, but the state in the store is still an object with a and b despite the new state was returned.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in

No response

Anything else?

No response

Do you want to create a pull request?

No

@racz-zsolt
Copy link

From what I know update performs a merge over the object in the store therefore the old properties won't be removed. I believe you should switch to method store.replace() that - as its name suggests - would replace the whole object. Alternatively you could try to set newState.a to an explicit undefined value.

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

No branches or pull requests

2 participants