Skip to content

Instantly share code, notes, and snippets.

@josephsavona
Created July 11, 2017 21:18
Show Gist options
  • Save josephsavona/a7eab7f576bf77677852211bd08cfbbb to your computer and use it in GitHub Desktop.
Save josephsavona/a7eab7f576bf77677852211bd08cfbbb to your computer and use it in GitHub Desktop.
Defer loading a QueryRenderer until after mount (useful for client only)
class DelayedQueryRenderer extends Component {
constructor(props, context) {
super(props, context);
this.state = {query: null}; // don't fetch anything initially
}
componentDidMount() {
this.setState({query: this.props.query}); // fetch after mount
}
componentWillReceiveProps(nextProps) {
this.setState({query: nextProps.query});
}
render() {
return (
<QueryRenderer
{...this.props} // probably safer to whitelist
query={this.state.query}
/>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment