I need to put slugs in my Header component which is reusable in all the site inside the layout:
const Layout = ({ children }) => {
return (
<>
<Header />//////////this one.
{children}
<Footer />
</>
);
};
My slugs goings from the server side and I need to dynamically fetch them only one time in the header.
Inside the header something like:
categoriesLinks.map(category=> {
return <div>{category.SLUG}</div>
})
But because it's a reusable component I don't know how and where to invoke the getServerSideProps or getStaticProps.
- if I use the index component for example I need to fetch data in every component
- if I tried to fetch it inside
getInitialPropsin the_app, it doesn't get it (getundefined)
What is the right way to handle this? It seems like a really big issue and I couldn't find the right solution for this.