Skip to content

Instantly share code, notes, and snippets.

@andrisgauracs
Last active December 30, 2018 22:01
Show Gist options
  • Select an option

  • Save andrisgauracs/1f517f6315594cafb96927aff1cd44c2 to your computer and use it in GitHub Desktop.

Select an option

Save andrisgauracs/1f517f6315594cafb96927aff1cd44c2 to your computer and use it in GitHub Desktop.
Traditional React asynchornous data call
class TraditionalAsyncExample extends Component {
constructor(props) {
super(props);
this.state = {
loading: true,
resource: undefined
}
}
componentDidMount() {
fetch(`{resourse}`).then((e)=>{
this.setState({loading:false, resource: e})
})
}
render() {
let { loading, resource } = this.state;
return (loading ? <div>Loading...</div> : <div>{resource}</div>);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment