I am buiding a website using next.js and I am trying to wrap my head around the following "problem". I have some static data (website text) that needs to be fetched from an API endpoint (Headless CMS).
For individual pages I use getInitialProps to fetch the required data. However I also have a Footer component in my main layout. Both layout and the Footer component have no getInitialProps solution, so how to deal with this in a "nice" way?
Some solutions I thought of:
- I can use componentDidMount to do a client side fetch for the data in the footer component (But I really want to server fetch / make it static).
- Move the footer to each page and have
getInitialPropsavailable, adding some HOC to prevent rewriting all the code. - As I said the data is static so make it available globally through server.js or _document.js (I don't know how to accomplish this though).
Anyone that can point me in the right direction?