我可以从 react redux 的动作中分派(类型和有效负载)吗?或者这是一个不好的做法?
Can I have a dispatch (type and payload) out of an action at react redux ? Or it's a bad practice?
我现在已经知道这段代码可以工作了,但我怀疑这是否是一种不好的做法。
我可以从动作中获取调度传递类型和负载吗?
await store.dispatch({
type: MY_TYPE,
payload: myPayload
})
或者这是一种不好的做法? (为什么)
(我的猜测)只有动作可以使用类型和有效负载分发数据(?)
根据此处的 Redux 文档:https://redux.js.org/recipes/reducing-boilerplate#action-creators
Action creators have often been criticized as boilerplate. Well, you don't have to write them! You can use object literals if you feel this better suits your project.
看起来完全没问题;但如果你继续阅读,他们会解释使用动作创建器而不是对象字面量的好处:
Action creators let you decouple additional logic around dispatching an action, from the actual components emitting those actions.
我现在已经知道这段代码可以工作了,但我怀疑这是否是一种不好的做法。
我可以从动作中获取调度传递类型和负载吗?
await store.dispatch({
type: MY_TYPE,
payload: myPayload
})
或者这是一种不好的做法? (为什么)
(我的猜测)只有动作可以使用类型和有效负载分发数据(?)
根据此处的 Redux 文档:https://redux.js.org/recipes/reducing-boilerplate#action-creators
Action creators have often been criticized as boilerplate. Well, you don't have to write them! You can use object literals if you feel this better suits your project.
看起来完全没问题;但如果你继续阅读,他们会解释使用动作创建器而不是对象字面量的好处:
Action creators let you decouple additional logic around dispatching an action, from the actual components emitting those actions.