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 theTodo
component 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.
selectStudent
which will have one argument - student object. Also this method might usesetState
with 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:
selectedStudent
which value will bethis.state.selectedStudent
- when modal get closed - set
selectedStudent
tonull
again
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"