Skip to content

Instantly share code, notes, and snippets.

@SuperAL
Last active February 27, 2018 09:50
Show Gist options
  • Select an option

  • Save SuperAL/5f16449dce700998e2149ae8d34a706f to your computer and use it in GitHub Desktop.

Select an option

Save SuperAL/5f16449dce700998e2149ae8d34a706f to your computer and use it in GitHub Desktop.
Simple Notes
class MyComp extends Component {
// default state
state = { fetching: 0 }
componentWillMount() {
// Setting state here won't trigger re-render
this.setState({ fetching: 1 });
}
componentDidMount() {
// fetching data
dispatch(yourAction()).then(res => {
// Setting state in this method will trigger a re-rendering.
this.setState({ fetching: 0 });
});
// It's fine to setState here if you need to access
// the rendered DOM, or alternatively you can use the ref functions
}
render() {
if (this.state.fetching) return <Loader />
return (
<div> // your data are loaded </div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment