小编gol*_*nus的帖子

无法在反应钩子中更新 setInterval 内的状态

我想在 setinterval() 中每秒更新一次状态,但它不起作用。我是 React hook 的新手,所以无法理解为什么会发生这种情况。请查看以下代码片段并给我建议。

// State definition

const [gamePlayTime, setGamePlayTime] = React.useState(100);
let targetShowTime = 3;
.........................
// call function
React.useEffect(() => {
    gameStart();
  }, []);
.............

const gameStart = () => {
    gameStartInternal = setInterval(() => {
      console.log(gamePlayTime); //always prints 100
      if (gamePlayTime % targetShowTime === 0) {

        //can not get inside here

        const random = (Math.floor(Math.random() * 10000) % wp("70")) + wp("10");
        const targetPosition = { x: random, y: hp("90") };
        const spinInfoData = getspinArray()[Math.floor(Math.random() * …
Run Code Online (Sandbox Code Playgroud)

setinterval reactjs react-hooks

13
推荐指数
4
解决办法
4535
查看次数

如何在世博会中扫描文档?

我正在使用 Expo 构建移动应用程序,并且应该实现文档扫描仪功能。但我找不到实施扫描文档的解决方案。我只能看到React Naive 的react-native-document-scanner npm 库,而看不到Expo 的npm 库。

如果有人有好的解决方案,请帮助我...

谢谢

reactjs react-native expo

7
推荐指数
1
解决办法
2177
查看次数

如何在 react native (expo) 中获取点击事件(单、双、长)?

我正在使用 React Native 中的几个点击事件(单、双、长)制作按钮。我已经使用了 Touchable 组件,并且使用时间延迟获得了这些事件。但这不是一个好的解决方案,并且存在一些问题。就是当我双击时,单个事件同时发生。在这种情况下,我必须删除单击事件并获得唯一的双击事件。有没有其他好的解决办法?

react-native touchableopacity expo

1
推荐指数
1
解决办法
5265
查看次数