Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Youtube in React: fetching search results in lifecycle functions
/* ... */
class Search extends React.Component {
componentDidMount() {
if (!this.getSearchQuery()) {
// redirect to home component if search query is not there
this.props.history.push('/');
}
this.searchForVideos();
}
componentDidUpdate(prevProps) {
if (prevProps.youtubeApiLoaded !== this.props.youtubeApiLoaded) {
this.searchForVideos();
}
}
/* ... */
}
/* ... */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.