import Container from '@material-ui/core/Container'; import Typography from '@material-ui/core/Typography'; import React, { Fragment, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import { useDispatch, useSelector } from 'react-redux'; import CoursesSlider from '../../components/CoursesSlider'; import CoursesTabs from '../../components/CoursesTabs'; import HeroContent from '../../components/HeroContent'; import { getDiscoveryItemsRequested } from '../../redux/discoveryItems/actionCreators'; import { State } from '../../redux/rootReducer'; import useStyles from './styles'; const Home = () => { const classes = useStyles(); const { t } = useTranslation(); const { bestSellers, mostViewed } = useSelector( ({ discoveryItems }: State) => discoveryItems ); const dispatch = useDispatch(); const getDiscoveryItems = () => dispatch(getDiscoveryItemsRequested()); useEffect(() => { const shouldFetchData = [ bestSellers.courses, bestSellers.categories, mostViewed.courses, ].some(items => items.length === 0); if (shouldFetchData) { getDiscoveryItems(); } }, []); return ( {t('home.exploreOurBestsellers')} {t('home.studentAreViewing')} ); }; export default Home;