Created
June 20, 2017 02:13
-
-
Save alexhawkins/05b43689aab3a5ae1d23c12d489cb792 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
class AsyncAwait extends React.Component { | |
constructor() { | |
super() | |
this.state = {} | |
} | |
async componentDidMount() { | |
const res = await this.context.api.fetch('/logout', { method: 'POST' }).then(() => { | |
this.context.api.environment.getStore().getSource().clear(); | |
//this.context.router.push(location.pathname); | |
}); | |
} | |
logout = (event) => { | |
event.preventDefault(); | |
this.context.api.fetch('/logout', { method: 'POST' }).then(() => { | |
this.context.api.environment.getStore().getSource().clear(); | |
history.push(history.location); | |
}); | |
}; | |
setStateAsync(state) { | |
return new Promise((resolve) => { | |
this.setState(state, resolve) | |
}) | |
} | |
render() { | |
return ( | |
<div | |
My IP is {this.state.ipAddress || 'Unknown'} | |
</div> | |
) | |
} | |
} | |
export default AsyncAwait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment