【发布时间】:2022-08-14 17:47:29
【问题描述】:
当onLongPress 触发时,我正在尝试更新我的状态。
我在 setState 之后立即打印结果,但它什么也没显示(在第一次按下时)
代码:
const [pressedImagesm setPressedImages] = useState([]);
...
onLongPress={() => {
setPressedImages(oldArray => [...oldArray, { [index]: true }]);
console.log(pressedImages);
}}
-
这回答了你的问题了吗? React, state setter not updating the value
标签: react-native state