zedArt
zedArt

Reputation: 487

componentDidMount() : call function after getItem from asyncStorage

I have to send an codeActivation with my API after calling this codeActivation from asyncStorage so I use this code:

  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

  }

how to call pwHash after setting my codeActivation from asyncStorage in this.state.codeActivation ?

Upvotes: 0

Views: 63

Answers (1)

Bilal Shah
Bilal Shah

Reputation: 1265

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);
  }

you can call it like this or you can just ignore setInterval() if that is not you need.

Upvotes: 1

Related Questions