top | item 23423467

One Cool Trick to Simplify Reducer Functions

4 points| ericelliott | 5 years ago |medium.com

1 comment

order

acemarke|5 years ago

Note that our official Redux Toolkit package [0] already uses Immer by default, and we have recommended using Immer with Redux in our Style Guide docs page [1]. (We also specifically recommend _against_ using Immutable.js in that page as well.)

Fun fact: because reducers are _just_ plain functions, there's not actually anything Redux-specific about them. That means you can use any reducer with React's `useReducer` hook as well. I've used RTK's `createSlice` function to generate strongly-TS-typed reducers for use in React components a number of times.

[0] https://redux-toolkit.js.org

[1] https://redux.js.org/style-guide/style-guide#use-immer-for-w...