From the course: Master Next.js by Building Scalable Apps with Routing, Databases, and Performance

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Rendering users in the table

Rendering users in the table

Now, let's work on rendering all the users in the users route. So we had already created the table. Now we just need to fetch the data from the database and render it. So let's create the server action to fetch the user data first. I'll say export const getUsers is equal to async because we will need to use await for the db methods and the arrow function const users is equal to await db dot admin user dot find many and we'll say return users. So the server action is complete. Now in the component where we have the users table, I'll take a constant and store all the users in it. I'll say const users is equal to await get users. And let me display it by saying console log users. Now let's save the code and check the output. I'll open the terminal and there we have the list of users displayed. Now we will render this very list in the above table. So let's start by creating a code block where we'll traverse and render the users array. the t body tag first, and then the curly brackets. And…

Contents