Skip to content

Instantly share code, notes, and snippets.

@tapir
Created December 31, 2018 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tapir/c0b0f75d771f77a3d5b0512f67eb5835 to your computer and use it in GitHub Desktop.
Save tapir/c0b0f75d771f77a3d5b0512f67eb5835 to your computer and use it in GitHub Desktop.
test.js
export default class HomeScreen extends React.Component {
constructor(props) {
super(props);
this.state = {token: ''};
this.getToken = this.getToken.bind(this);
getToken();
}
getToken() {
AsyncStorage.getItem('JWT_TOKEN')
.then((token) => {
console.warn(token); // Success
this.setState({token: token});
})
.catch((error) => this.toast(error));
}
componentDidMount() {
console.warn(this.state.token); // Fail
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment