Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AsyncStorage not fulfilling promise #17282

Closed
ghost opened this issue Dec 20, 2017 · 2 comments
Closed

AsyncStorage not fulfilling promise #17282

ghost opened this issue Dec 20, 2017 · 2 comments
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.

Comments

@ghost
Copy link

ghost commented Dec 20, 2017

Issue
I am using NetInfo and asyncstorage in my project.
The promise of NetInfo works fine, after getting the response from NetInfo I'm getting the value of a flag from AsyncStorage.The issue is sometimes the response (flag from Asyncstorage) is resolved, sometimes it doesn't. It happens on the very first launch of the application always.
And my application requires that the promise should be returned from Asyncstorage .

The following code executes inside React Native component lifecycle's:
componentWillMount(){
this.setState({loading:true});
NetInfo.isConnected.fetch().then(isConnected => {
console.log('isconnected ' + (isConnected ? 'online' : 'offline'));
(isConnected?this.setState({net:true}):this.setState({net:false}))
// Alert.alert('Netwrok',this.state.net)

}).then(()=>{
global.internetStatus=this.state.net;
console.log('going in db');

 AsyncStorage.getItem('@DATABASE', (err, result) => {
   this.setState({data:result})
   console.log('result is',result,err);
  // Alert.alert('Database',err,result)
   if(result==1&&this.state.net==false){
    console.log('1st case',result,this.state.net);
    }
    else if(result==1&&this.state.net==true){
      console.log('2st case',result,this.state.net);
      
    }
    else if(result!==1&&this.state.net==true){
      console.log('3st case',result,this.state.net);
      this.getData();                
    }
    else{
      console.log('4th case',result,this.state.net);
    }
 });

})

Environment:
OS: macOS Sierra 10.13.1
Node: 8.4.0
npm: 3.10.10
Watchman: 4.7.0

Packages:
react-native: 0.50.3
react: 16.0.0

Target Platform:Android(6.0)

@react-native-bot
Copy link
Collaborator

@facebook-github-bot no-template

@facebook-github-bot
Copy link
Contributor

Hey @goravsehrawat, thanks for posting this! It looks like your issue is missing some required information. Can you please add all the details specified in the Issue Template? This is necessary for people to be able to understand and reproduce your issue. I am going to close this, but please feel free to open a new issue with the additional information provided. Thanks!

How to ContributeWhat to Expect from Maintainers

@facebook-github-bot facebook-github-bot added the Ran Commands One of our bots successfully processed a command. label Dec 20, 2017
@facebook facebook locked as resolved and limited conversation to collaborators Dec 20, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Dec 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

3 participants