简体   繁体   English

在 react-redux 减速器中使用 useDispatch() 钩子?

[英]Use useDispatch() hook inside the react-redux reducer?

I want to fire action from a reducer.我想从减速器触发动作。 The action will set/unset the loader state.该操作将设置/取消设置加载程序状态。

Here is an example of my reducer这是我的减速器的一个例子

const ABC = reducerWithInitialState(initialState)
     .case(getABCAction.started, (state) => {
         const dispatch = useDispatch();
         dispatch(setAppLoader(true))
         return (state);
     });

However, it says that its an invalid hook call.但是,它说它是一个无效的钩子调用。

Is there any workaround for this?有什么解决方法吗?

Rohan,你在reducer里面,你可以完全控制返回任何你想要的状态,你不必再分派任何动作,你可以对状态“做”你想做的任何事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM