Skip to content

Instantly share code, notes, and snippets.

@radicalloop
Created March 2, 2020 12:55
Show Gist options
  • Save radicalloop/9f08884faa9e5bfbd0d4ff3adbe3f4ca to your computer and use it in GitHub Desktop.
Save radicalloop/9f08884faa9e5bfbd0d4ff3adbe3f4ca to your computer and use it in GitHub Desktop.
Index Page (Next.js)
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