How To Change Table Data In React With Buttons In Modal
Hi i have problem with my react components. I don't know how to update element in table from shared modal for all elements. In my real case i have students timetable and i have to
Solution 1:
This scenario might work for you:
- add
selectedStudent: null,to theTodocomponent state - remove button which have text "Launch vertically centered modal"
- add new button to each row of students. Name it something like "Select"
- add new method to Todo component e.g.
selectStudentwhich will have one argument - student object. Also this method might usesetStatewith callback. Callback will open the modal (by changing statemodal: true). This method is what will be fired when you click on "Select" button - pass new prop to the modal:
selectedStudentwhich value will bethis.state.selectedStudent - when modal get closed - set
selectedStudenttonullagain
If something seems confusing here or you need further explanation please ask
N.B. you might also remove modal key from state and conditionally render modal only when selectedStudent is an object. When selectedStudent is null - modal should be closed.
Post a Comment for "How To Change Table Data In React With Buttons In Modal"