HOCs examples
A few HOCs are provided as utilities:
withApollo
: Wraps a page into anApolloProvider
and handles state rehydration between CSR navigation.
Can be used with any rendering mode (expect SSG by default).
Do not usegetInitialProps
by default, only whenuseGetInitialProps: true
(meant for pages usinggetInitialProps
only).withHOCTemplate
: Template for quickly getting started with a new HOC, meant as a utility. Feel free to customise it!
withApollo
This HOC is necessary for all pages in the demo, because all pages need data that are used by shared component (i.e: Nav, Footer).
If you don't need to fetch data from a data source, then you don't need to use it.
1
2
3
4
5
6
7
// Example for a page using getStaticProps or getServerSideProps
export default (ExampleHomePage);
// Example for a page using getInitialProps
export default withApollo({ useGetInitialProps: true })(ExampleHomePage);
We don't actually use the
useGetInitialProps
option anywhere in this demo, because we don't use getInitialProps
anymore.