Skip to content

Instantly share code, notes, and snippets.

@productioncoder
Created December 17, 2018 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save productioncoder/33f271d44a31b7546dfbe10e19df1eaa to your computer and use it in GitHub Desktop.
Save productioncoder/33f271d44a31b7546dfbe10e19df1eaa to your computer and use it in GitHub Desktop.
Youtube in React: dynamically creating video grids in Home Content
/*...*/
import {getMostPopularVideos, getVideosByCategory} from '../../../store/reducers/videos';
class HomeContent extends React.Component {
/* ... */
getVideoGridsForCategories() {
const categoryTitles = Object.keys(this.props.videosByCategory || {});
return categoryTitles.map((categoryTitle,index) => {
const videos = this.props.videosByCategory[categoryTitle];
// the last video grid element should not have a divider
const hideDivider = index === categoryTitles.length - 1;
return <VideoGrid title={categoryTitle} videos={videos} key={categoryTitle} hideDivider={hideDivider}/>;
});
}
/* ... */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment