我尝试在react native with react native navigation中页面成为焦点后立即更新状态,但是如果我记录值,仍然会导致旧的状态。
useFocusEffect(
React.useCallback(() => {
if (route.params?.key !== null) {
setKey(route.params?.key);
console.log(route.params?.key) //These two console log give different values
console.log(key);
setLastTokenDate(route.params?.date);
}
}, [route.params?.chiave, route.params?.data]),
);
1条答案
按热度按时间cygmwpex1#
试试这个:
我想你会发现你错在哪里