Created
July 11, 2017 21:18
-
-
Save josephsavona/a7eab7f576bf77677852211bd08cfbbb to your computer and use it in GitHub Desktop.
Defer loading a QueryRenderer until after mount (useful for client only)
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
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