Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.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
React native clearInterval不';我不能在办公室工作_React Native_Setinterval_Clearinterval - Fatal编程技术网

React native clearInterval不';我不能在办公室工作

React native clearInterval不';我不能在办公室工作,react-native,setinterval,clearinterval,React Native,Setinterval,Clearinterval,我已经通过功能组件编写了一个进度条代码(在android和IOS中),有三个按钮,其中一个启动进度条,另一个停止,最后一个按钮重新启动进度条。停止按钮不起作用,clearInterval似乎不起作用, 请你看一下,帮我解决这个问题好吗 const MainFunc = (props) => { let [ProgresValue, setProgresValue] = useState(0); let IntValue = ''; const StartP

我已经通过功能组件编写了一个进度条代码(在android和IOS中),有三个按钮,其中一个启动进度条,另一个停止,最后一个按钮重新启动进度条。停止按钮不起作用,clearInterval似乎不起作用, 请你看一下,帮我解决这个问题好吗


const MainFunc = (props) => {



    let [ProgresValue, setProgresValue] = useState(0);

    let IntValue = '';
    const StartProgress = () => {

        IntValue = setInterval(() => {
            if (ProgresValue <= 1) {

                setProgresValue(ProgresValue = ProgresValue + 0.01)

            }

        }, 100);

    }



    const StopProgress = () => {

        clearInterval(IntValue)


    }


    const RestartProgress = () => {

        setProgresValue(ProgresValue = 0)


    }





    return (
        <Fragment>
            <Text>Progress Bar:{parseFloat((ProgresValue * 100).toFixed(3))}%</Text>

            {
                (Platform.OS === 'android')
                    ?
                    (<ProgressBarAndroid
                        styleAttr='Horizontal'
                        indeterminate={false}
                        progress={ProgresValue}



                    />)
                    :
                    (<ProgressViewIOS
                        progress={ProgresValue}

                    />)


            }

            <TouchableHighlight onPress={StartProgress} style={styles.button}><Text style={{ color: 'white', textAlign: 'center' }}>Start Prgress</Text></TouchableHighlight>
            <TouchableHighlight onPress={StopProgress} style={styles.button} ><Text style={{ color: 'white', textAlign: 'center' }} >Stop Progress</Text></TouchableHighlight>
            <TouchableHighlight onPress={RestartProgress} style={styles.button}><Text style={{ color: 'white', textAlign: 'center' }} >Restart Progress</Text></TouchableHighlight>



        </Fragment>


    )



}


常量MainFunc=(道具)=>{
让[ProgresValue,setProgresValue]=useState(0);
让IntValue='';
常量StartProgress=()=>{
IntValue=setInterval(()=>{
if(ProgresValue{
清除间隔(IntValue)
}
const RestartProgress=()=>{
setProgresValue(ProgresValue=0)
}
返回(
进度条:{parseFloat((ProgresValue*100).toFixed(3))}%
{
(Platform.OS==='android')
?
()
:
()
}
启动程序
停止进展
重新启动进程
)
}

这能回答你的问题吗?不,伙计,不能。实际上我的统计数据正在更新,我的问题是在另一个函数中定义的clearInterval不起作用,无法停止setInterval,你知道吗?我也有同样的问题,我只是使用setTimeout,然后更新值,然后使用useEffect挂钩创建另一个setTimeout当setTimeout回调中的值发生变化时。这回答了你的问题吗?不,伙计,它没有。实际上我的统计数据正在更新,我的问题是在另一个函数中定义的clearInterval不起作用,无法停止setInterval,你知道吗?我遇到了相同的问题我刚刚使用了setTimeout,然后更新该值,然后在setTimeout回调内的值更改时,使用useEffect挂钩创建另一个setTimeout。