Last active
January 8, 2017 12:36
-
-
Save simevidas/79b89ffad1101be50608a25f38314a7c to your computer and use it in GitHub Desktop.
Autobound async class method (minimal example in Preact)
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 { h, Component, render } from 'preact'; | |
import autobind from 'autobind-decorator'; | |
import 'normalize.css'; | |
import 'App.scss'; | |
import Header from 'Header'; | |
class App extends Component { | |
@autobind async fetchData() { | |
let response = await fetch('/test.json'); | |
let data = await response.json(); | |
this.setState({ value: data.value }); | |
} | |
render({}, { value }) { | |
return ( | |
<div> | |
<Header>Testing async</Header> | |
<main> | |
<button onClick={ this.fetchData }>Test async method</button> | |
<data>{ value }</data> | |
</main> | |
</div> | |
); | |
} | |
} | |
render(<App />, document.body); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment