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