Skip to content

Make clearer how to not mutate state when you want to. #725

Closed
@klequis

Description

@klequis

Here is a suggestion that would make the doc clearer to me. Don't know if that is the majority of the user base. I have only read 80% of the doc so could have missed something, so apology if I did.

I got from the doc that you 'could mutate state or not but not both' and the doc was clear to me on how to mutate state but no on how to not mutate when you didn't want to.

This thread made it clear to me: #242

If I'm understanding things correctly:

mutate state

state.something = something

don't mutate

return newState

I accidentally did (i.e., not mutation0

state = newState

And spent a while trying to figure how why the store was not updating.

hope I got that work but my code is working now

I think a useful addition would be to

  1. make it clearer that in the rare case you don't want to mutate state you just need the return keyword with the new state.
  2. I also didn't see any place that said what would the result will be if you did state = newState, which in my case was the store didn't update.
  3. A third thing I didn't get from the doc was if you could make the mutate vs not mutate choice on a per reducer basis rather than on some larger slice or project level. Making point Create LICENSE #1 clearer would solve this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions