Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 在redux中更新状态后,如何执行回调?_Reactjs_Typescript_Redux - Fatal编程技术网

Reactjs 在redux中更新状态后,如何执行回调?

Reactjs 在redux中更新状态后,如何执行回调?,reactjs,typescript,redux,Reactjs,Typescript,Redux,在redux中是否可以执行与react中的更新状态类似的函数?我的意思是将回调函数作为参数传递给action creator,action creator将在状态更新后执行,在这个回调中,我将有可能访问更新的状态?我已经搜索了很多关于这个的帖子,但是没有任何成功。为什么在redux中状态更新后执行回调如此困难?在react中,这是非常简单的,我们可以简单地做 this.setState({isLoading:false},()=>{ console.log(this.state.isLoadin

在redux中是否可以执行与react中的更新状态类似的函数?我的意思是将回调函数作为参数传递给action creator,action creator将在状态更新后执行,在这个回调中,我将有可能访问更新的状态?我已经搜索了很多关于这个的帖子,但是没有任何成功。为什么在redux中状态更新后执行回调如此困难?在react中,这是非常简单的,我们可以简单地做

this.setState({isLoading:false},()=>{
console.log(this.state.isLoading)
});

可用于同步分派操作。您还可以使用生命周期方法“componentDidUpdate”或“getDerivedStateFromProps”检查props和状态,并根据其当前值执行其他函数


Codesandbox演示如何使用componentDidUpdate-

一种方法是在redux saga中使用put效应,然后使用select效应。@michal16511,如果下面的答案对您有效,请将其标记为已接受。