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
React native React Redux不更新SetInterval上的值_React Native_Redux_React Redux - Fatal编程技术网

React native React Redux不更新SetInterval上的值

React native React Redux不更新SetInterval上的值,react-native,redux,react-redux,React Native,Redux,React Redux,在自定义组件上,如果我通过onPress函数分派一个新值,它就会工作。如果我将其设置为设置间隔或后台计时器,则新值不会更新 减速器: import initialState from './InitialState'; export function setData(type, data) { if (!data) var data = ''; return { type: type, state: data } } const red

在自定义组件上,如果我通过
onPress
函数分派一个新值,它就会工作。如果我将其设置为
设置间隔
后台计时器
,则新值不会更新

减速器:

import initialState from './InitialState';

export function setData(type, data) {
    if (!data) var data = '';
    return {
        type: type,
        state: data
    }
}

const reducer = (state = initialState, action) => {
    console.log("action che arriva al reducer", action)

    switch (action.type) {
        case 'setInitialState':
            return initialState
        case 'setTipology':
            return {
                ...state, typology: action.state
            }
            case 'setTimer':
                return {
                    ...state, timer: action.state
                }
    }

    return state;
}

export default reducer  
自定义组件:

const Timer = ({
    title,
    action
}) => {
    const dispatch = useDispatch()
    const reduxState = useSelector(state => state)

    const timerFunction = (action) => {
        if (action == "start") {
            //dispatch(setData('setTimer', reduxState.timer  + 1000))
            BackgroundTimer.runBackgroundTimer(() => {
                dispatch(setData('setTimer', reduxState.timer + 1000))
            }, 1000);

        } else if (action == "end") {
            return BackgroundTimer.stopBackgroundTimer(); //after this call all code on background stop run.
        }
    }

    return (
        <>
            <TouchableOpacity
                onPress={() => timerFunction(action)}
                style={styles.cButton}
            >
                <Text style={styles.testo}>{title}</Text>
            </TouchableOpacity>
        </>
    )
}
在这个例子中,它不起作用。 有什么建议吗

( dispatch(setData('setTimer', reduxState.timer  + 1000)) )