DEV Community

Cover image for ReactJS ~Async Components~
Ogasawara Kakeru
Ogasawara Kakeru

Posted on

ReactJS ~Async Components~

・The async components are rendered on the server side to retrieve data by using async/await. This enables you to access data from the database, generate HTML with the retrieved data, and send it to the client side. This improves the rendering performance effectively.

async function AsyncPage({ id }) {
 //fetch data directly in the component
  const result = await db.sample.get(id); 

  return (
    <div>
      <h1>{result.title}</h1>
      <p>{result.content}</p>
    </div>
  );
}

Enter fullscreen mode Exit fullscreen mode

Top comments (0)