I've seen many questions relating to issues with getInitialProps
and getStaticProps
but haven't been able to solve my own.
I'm merely trying to load some json data (I console.logged it and know it's not undefined) and pass it to my Main
component:
import Card from "./components/Card";
import data from "../data/data.json";
const Main = ({ cards }) => {
return (
<div}>
{cards.map((card) => {
<Card key={card.id} card={card} />;
})}
</div>
);
};
Main.getInitialProps = async (context) => {
return {
props: { cards: data },
};
};
export default Main;
TypeError: Cannot read property 'map' of undefined
I tried with getStaticProps
as well, same issue.
What am I doing wrong?
data
comes from, I assume for simplicity. Make sure it is actually an array. – Dominik