79092644

Date: 2024-10-16 06:05:59
Score: 0.5
Natty:
Report link

Are you using App Router? if yes then use "use client" directive on top of the page. but I will suggest you that you should directly make fetch request on server side, so it will not need to use the hooks.


const getData = async () => {
  const res = fetch('https://jsonplaceholder.typicode.com/posts')
      if(!res.ok){
        notFound() // @next/navigation
      }
      const data =  await res.json()
      console.log(data);
      return data;

}
// This page becomes a async page for seerver side
const Projects = async ({}: Props) => {
const data = await getData()

  return (
        <DataList data={data} />
  );
};


export default DataPage;```
 // and use loading.tsx in app router for handling the Loading
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: Sharuk Sayyed