DEV Community

Discussion on: The Hitchhikers Guide to Refs

Collapse
 
selbekk profile image
selbekk

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:

<Table 
  rows={data} 
  onDeleteRow={removeRow} 
  onAddRow={addRow} 
/>

The Table component would then loop through the data and create the rows you need.

The addRow and removeRow functions would then change the data state variable.

Collapse
 
snmpboy profile image
Mitch Raful

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.

Thread Thread
 
selbekk profile image
selbekk

Yay!