React native componentDidMount():从异步存储中获取项后调用函数
从asyncStorage调用此codeActivation后,我必须使用API发送codeActivation,因此我使用以下代码: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 ' +
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);
}