How to share staticProps across Components in nextjs

221 views Asked by At

Im trying to build a website using nextjs. I thought it was a good pick for what im trying to do, but now im stuck.

I have a single api endpoint i want to call and fetch some static data. But the problem is that i need parts of the data all over my page - and what really seems to be the problem - all over my components.

For example i have <Navbar/> & <Sidebar/> Components that are conditionally rendered depending on screen size. Both need some of the data, but both are inside my <Layout/> Component.

Since getStaticProps can be only be exported from pages i have no idea how im supposed to get the data inside of these components.

From what i have learned i could use getStaticProps inside _app.js but with the downside that my pages can't be optimised anymore. But what does that mean? Whats the drawback doing that?

0

There are 0 answers