An Interest In:
Web News this Week
- April 20, 2024
- April 19, 2024
- April 18, 2024
- April 17, 2024
- April 16, 2024
- April 15, 2024
- April 14, 2024
January 19, 2022 08:17 pm GMT
Original Link: https://dev.to/yasin162/how-to-do-a-delete-request-in-react-1lf7
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.
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.
Original Link: https://dev.to/yasin162/how-to-do-a-delete-request-in-react-1lf7
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To