TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

One Cool Trick to Simplify Reducer Functions

4 pointsby ericelliottalmost 5 years ago

1 comment

acemarkealmost 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.)<p>Fun fact: because reducers are _just_ plain functions, there&#x27;s not actually anything Redux-specific about them. That means you can use any reducer with React&#x27;s `useReducer` hook as well. I&#x27;ve used RTK&#x27;s `createSlice` function to generate strongly-TS-typed reducers for use in React components a number of times.<p>[0] <a href="https:&#x2F;&#x2F;redux-toolkit.js.org" rel="nofollow">https:&#x2F;&#x2F;redux-toolkit.js.org</a><p>[1] <a href="https:&#x2F;&#x2F;redux.js.org&#x2F;style-guide&#x2F;style-guide#use-immer-for-writing-immutable-updates" rel="nofollow">https:&#x2F;&#x2F;redux.js.org&#x2F;style-guide&#x2F;style-guide#use-immer-for-w...</a>