Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.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
Javascript 反应本机状态更新和同步失败_Javascript_Reactjs_React Native - Fatal编程技术网

Javascript 反应本机状态更新和同步失败

Javascript 反应本机状态更新和同步失败,javascript,reactjs,react-native,Javascript,Reactjs,React Native,我尝试使用UserContext.js中的初始状态信息进行用户注册,并使用useReducer更改初始状态的值。但是,当文件Login.js首次呈现时,初始状态下的信息不会更新并返回null。有人能帮我解决这个问题吗 Login.js: const nodeRegistration = (aesKey, email, password) => { console.log(state) if (state.publicKey !== null) { c

我尝试使用UserContext.js中的初始状态信息进行用户注册,并使用useReducer更改初始状态的值。但是,当文件Login.js首次呈现时,初始状态下的信息不会更新并返回null。有人能帮我解决这个问题吗

Login.js:

const nodeRegistration = (aesKey, email, password) => {

    console.log(state)
    
    if (state.publicKey !== null) {
      const p = state.publicKey.slice(6, -14)

      const registerdata = "usnm=" + encodeURIComponent(email) + "&pswd=" + encodeURIComponent(password)
      + "&nt=65540&key=" + hexToBase64(p) + "&mac=" + state.uniqueMacId + "&lip=" + state.localIpAddress 
      + "&host=" + state.diviceInfo.diviceName + "&osn=" + state.diviceInfo.operatingSystemName + "&osv=" 
      + state.diviceInfo.operatingSystemVersion

      console.log(registerdata)
    }
  };
UserContext.js:

    const initialState = {
    
      regionKey: null,
      aesKey: null,
    }    

const reducer = (state, action) => {
      switch (action.type) {
        case 'get_regionInfo':
          return {
            ...state, 
            regionKey: action.payload.regionKey,
            aesKey: action.payload.aesKey
          }
        default:
          return state;
      }
    };

const getRegionInfo = dispatch => {
  return () => {
    API().get("https://center.ubiq.network/regiondata").then(res => {
      console.log(res.data[0])
      dispatch({ type: 'get_regionInfo', payload: {
        regionKey: res.data[0].node,
        aesKey: getAESKey(res.data[0].node)
      }})
    }).catch(err => {
      console.log(err)
    })
  }
}