Skip to content
Advertisement

delete button does not read id if modal added in ReactJS

I have created a CRUD application and successfully it is performing all the operations.

But when I try to create a modal so that it shows up a warning either to delete the id or not on clicking delete. And If I try to delete a particular id from the modal I’m unable to delete the selected item, else it is deleted the latest id in the list.

What might be the problem that is making me not delete a particular id from the list only when creating a modal.

Help me how I can make it work.

This is the button to open the warning modal:

JavaScript

This is the modal that opens after clicking delete:

JavaScript

In the above modal I have give the onclick event for button YES to delete the id selected, but the delete functionality is not working when I use it on a modal.

These are the button functionalities:

JavaScript

Please help me how I can achieve the functionality of deleting the particular id after modal opens, and let me know if you need any more details regarding my code.

Advertisement

Answer

I am new to react, i don’t know if my explanation will be correct, my theory is that the problem was this: You were rendering the modal for every record, and only the last modal remained.

I put the modal outside the loop, and i declared a useState to track the selected id to delete, it worked =D

Read.js :

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement