Skip to content

Instantly share code, notes, and snippets.

@productioncoder
Created November 24, 2018 11:45
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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