While it is certainly possible to manually create action objects everywhere, and write each type value by hand, defining reusable constants makes maintaining code easier.
我是真的不觉得 easy ,95% 的 action 都是用那么一两次。有没有同学遇到过 action 这个抽象真的有用的?
---- 背景 ----
写 redux action 写的很烦。zustand 这种更简单的,也需要 action 。所以干脆传了一个统一的匿名函数,利用 closure 直接拿了很多变量。但就报了这个 warning
reducer: (state, action) => {
if (!state) {
throw new Error("root state should not be empty");
}
let newState = { ...state };
if (action.type === "func") {
newState = produce(state, action.func); // import produce from 'immer'
}
return newState;
},
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.