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 i…


This content originally appeared on DEV Community and was authored by Yasin

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


This content originally appeared on DEV Community and was authored by Yasin


Print Share Comment Cite Upload Translate Updates
APA

Yasin | Sciencx (2022-01-19T20:17:19+00:00) How to do a delete request in react. Retrieved from https://www.scien.cx/2022/01/19/how-to-do-a-delete-request-in-react/

MLA
" » How to do a delete request in react." Yasin | Sciencx - Wednesday January 19, 2022, https://www.scien.cx/2022/01/19/how-to-do-a-delete-request-in-react/
HARVARD
Yasin | Sciencx Wednesday January 19, 2022 » How to do a delete request in react., viewed ,<https://www.scien.cx/2022/01/19/how-to-do-a-delete-request-in-react/>
VANCOUVER
Yasin | Sciencx - » How to do a delete request in react. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/01/19/how-to-do-a-delete-request-in-react/
CHICAGO
" » How to do a delete request in react." Yasin | Sciencx - Accessed . https://www.scien.cx/2022/01/19/how-to-do-a-delete-request-in-react/
IEEE
" » How to do a delete request in react." Yasin | Sciencx [Online]. Available: https://www.scien.cx/2022/01/19/how-to-do-a-delete-request-in-react/. [Accessed: ]
rf:citation
» How to do a delete request in react | Yasin | Sciencx | https://www.scien.cx/2022/01/19/how-to-do-a-delete-request-in-react/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.