Ok, here's my question. And I can't seem to get an answer from stackoverflow unless I paste code. I have a table component. I can use refs and remove rows from it as needed. My question is, should I be removing rows (and potentially adding them back) via Refs. Or should I attempt this some other way (useContext? Redux?). (The code questions will come if it's useContext and Redux.)
Hi Mitch! Iād typically avoid using refs for this sort of thing. Pass the data for each row in as an array to your table component, and work on that data set instead.
Thanks! That seems to be the way to go so I did. And in the process, made individual components for Cells, and Rows. It allowed to further generalize and use the table in with other components.
Ok, here's my question. And I can't seem to get an answer from stackoverflow unless I paste code. I have a table component. I can use refs and remove rows from it as needed. My question is, should I be removing rows (and potentially adding them back) via Refs. Or should I attempt this some other way (useContext? Redux?). (The code questions will come if it's useContext and Redux.)
Hi Mitch! Iād typically avoid using refs for this sort of thing. Pass the data for each row in as an array to your table component, and work on that data set instead.
Your API could look like this:
The Table component would then loop through the data and create the rows you need.
The
addRowandremoveRowfunctions would then change thedatastate variable.Thanks! That seems to be the way to go so I did. And in the process, made individual components for Cells, and Rows. It allowed to further generalize and use the table in with other components.
Yay!