【发布时间】:2020-04-22 09:37:17
【问题描述】:
我试图在调度之后运行方法,但是当我调度 redux 状态时,它在调度之后运行代码,然后完全调度。
<TouchableOpacity
onPress={() => {
dispatch(
addData({
name: "Test Name",
phone: "0000",
})
);
// dataReducer is the variable which returns state of reducer using selector
console.log("Added Data: " + JSON.stringify(dataReducer)); //returns []
}}
>
<Text>
{item.name}
</Text>
</TouchableOpacity>
如果我再次按下它会返回更新的数组。这意味着在 onpress 完全呈现后状态会更新。我希望 onPress 在数据完全发送之前不要完成,然后继续下一行。我检查了 useDispatch() 没有附加回调方法。请指导什么是更好的方法。
【问题讨论】:
-
找到解决方案了吗?
-
还没有我刚刚发布的问题
标签: reactjs react-native react-redux react-hooks dispatch