Settings

Theme

One Cool Trick to Simplify Reducer Functions

medium.com

4 points by ericelliott 6 years ago · 1 comment

Reader

acemarke 6 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...

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection