Created
March 2, 2020 12:55
-
-
Save radicalloop/9f08884faa9e5bfbd0d4ff3adbe3f4ca to your computer and use it in GitHub Desktop.
Index Page (Next.js)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import withLayout from "../components/Layout"; | |
import HomeComponent from "../components/home/Home"; | |
import { addHomePage } from '../store/pages/action'; | |
import api from '../api'; | |
let Index = (props) => <HomeComponent {...props} />; | |
Index.getInitialProps = async ({ store, isServer }) => { | |
let homePage = store.getState().pages.homepage; | |
if (Object.keys(homePage).length === 0) { | |
const { data } = await api.get('pages/homepage'); | |
homePage = data; | |
store.dispatch(addHomePage(homePage)); | |
} | |
return { homePage } | |
} | |
export default withLayout(Index); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment