DEV Community

Discussion on: Redux Toolkit - The Standard Way to Write Redux

Collapse
 
lowla profile image
Laureline Paris

Alohaaa thanks for sharing.
However I have a question : it seems like you break the rule of immutably regarding the update of count by affecting straight away the state ( state.count++ / state.count-- )
Is this way recommended with reduxjs/toolkit ( which would mean the toolkit abstract the good practice for people and would handle itself the return of a new value ) or is this just a mistake ?

Collapse
 
lowla profile image
Laureline Paris

After practicing a bit I had my answer:

  • createSlice and createReducer are using internally Immer ( package handling immutable data structure. ) : this is why it we can provide the updated value like so.

the toolkit is really nice however this is unfortunate that such official opinionated tool implies confusing habits ( such as re-assigning the value straight away affected ) whereas the the fundamental principal of the mature react library was enforcing the habit to not mutate directly the value pre and post hooks.