nextjs-basics icon indicating copy to clipboard operation
nextjs-basics copied to clipboard

Taking data from a single json file

Open nimit2801 opened this issue 4 years ago • 0 comments

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 ?

nimit2801 avatar Jun 27 '21 07:06 nimit2801