DEV Community

Yasin
Yasin

Posted on

How to do a delete request in react

Before check to make sure your backend is set up correctly before starting. Meaning your routes has a destroy route and the controller has the method.

Make a function that every single time it's run fetches and deletes the object you want delete. So in my case I call it deletePost with the parameters of postId. That way it will match whatever route that is has the corresponding postId.

Image description

Make a button that has an onClick with an anonymous function that takes in the function you just made and past through the data needed for the function. So in my situation it was a post.Id.

Image description

Top comments (0)