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;
},