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.

Deleting user by confirmation popup

Deleting user by confirmation popup

In the previous lecture, we have successfully handled the confirmation popup from the screen component. Now, I want to trigger the delete user action while clicking on the confirmation button of the popup. We already have the handle delete function, so I will pass this function as a prop by saying handle confirm is equal to handle delete. Next, I will go to the confirmation popup component and destructure by saying comma handle confirm and using that function by writing onclick is equal to handle confirm. Now let's save the code and I'll open the screen component to modify handle delete function. I will close the popup after deleting the user by writing set is delete model open and will pass false inside. But we cannot get selected ID from the parameter. So I will take a state called const selected ID comma set selected ID is equal to use state. And I will store the user id in that state while clicking on the delete icon. So I will say setSelectedId and in the brackets user.id. That's…

Contents