TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

One Cool Trick to Simplify Reducer Functions

4 点作者 ericelliott将近 5 年前

1 comment

acemarke将近 5 年前
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>