Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.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 componentDidMount():从异步存储中获取项后调用函数_React Native - Fatal编程技术网

React native componentDidMount():从异步存储中获取项后调用函数

React native componentDidMount():从异步存储中获取项后调用函数,react-native,React Native,从asyncStorage调用此codeActivation后,我必须使用API发送codeActivation,因此我使用以下代码: componentDidMount() { AsyncStorage.getItem(CODEACTIVATION_STORED) .then(code => { this.setState({ codeActivation: code}) console.log('t2 ' +

从asyncStorage调用此codeActivation后,我必须使用API发送codeActivation,因此我使用以下代码:

  componentDidMount() {
    AsyncStorage.getItem(CODEACTIVATION_STORED)
        .then(code => {
            this.setState({ codeActivation: code})
            console.log('t2 ' + this.state.codeActivation); << output : t1 544875962

    });
    AsyncStorage.getItem(TOKEN_STORED)
        .then(code => {
            this.setState({ Token: code})
    });
    console.log('t1 ' + this.state.codeActivation); << output: t1 
      this.pwHash(); << where I use this.state.codeActivation

  }
componentDidMount(){
AsyncStorage.getItem(已存储代码激活)
。然后(代码=>{
this.setState({codeActivation:code})
console.log('t2'+this.state.codeActivation){
this.setState({Token:code})
});
console.log('t1'+this.state.codeActivation);
componentDidMount(){
设置间隔(()=>{
AsyncStorage.getItem(已存储代码激活)
。然后(代码=>{
this.setState({codeActivation:code})
console.log('t2'+this.state.codeActivation){
this.setState({Token:code})

console.log('t1'+this.state.codeActivation);我需要令牌,我必须设置令牌和codeActivation不仅codeActivationI使用了setTimeout,而且只在这个.pwHash上。谢谢你,我还更新了代码,你可以使用这个.pwHash
componentDidMount() {
    setInterval(() => {
      AsyncStorage.getItem(CODEACTIVATION_STORED)
        .then(code => {
            this.setState({ codeActivation: code})
            console.log('t2 ' + this.state.codeActivation); << output : t1 544875962



    });
    AsyncStorage.getItem(TOKEN_STORED)
        .then(code => {
            this.setState({ Token: code})
      console.log('t1 ' + this.state.codeActivation); << output: t1 
      this.pwHash(); << where I use this.state.codeActivation && this.state.token
    });
    }, 5000);
  }