I am new to Next. I’ve run into a question about server components that I can’t figure out the answer to.
In an async server component, if I run some function on data used in the render, does it get computed before the render happens? Do I need to set up this function return as a promise? Do I need to create a client sub-component that uses classic useState and useEffect to ensure these functions are run on the data before the render? Or is this fine because it is waiting for the for the function to run before rendering?
Example:
export default async function Home() {
const posts = await db.post.findMany();
const doSomeStuffToPosts = (posts) => {
bla bla bla;
return someNewData;
};
const newPostsData = doSomeStuffToPosts(posts);
return (
{newPostsData.map((newPost) => <IndividualPostData newPost={newPost} />
);
}