nextjs-basics
nextjs-basics copied to clipboard
Taking data from a single json file
I was just exploring the project and wondered it would be better fetching from a single json file and single json file and fetched data from there.
export async function getServerSideProps({ params }) {
const req = await fetch(`http://localhost:3000/cars.json`);
const data = await req.json();
const carData = data[params.id];
return {
props: { car: carData },
};
}
Would be fun to use this. Thoughts @codediodeio ?