If I understand your question correctly, perhaps you could define a generic <TableRow> component as shown below, where:
- the same general table row structure is defined and can be reused
- the contents of the first
<td> of the <TableRow> can be specified externally, allowing you to render dynamic content into the common surrounding row structure
TableRow
/* Define TableRow functional component. This allows reuse of code for general row
structure while also allowing external control over the contents of the first <td>
*/
const TableRow = (props) => {
const { education } = props;
return (<tr key={education.id}>
{ /* Render the children components of this TableRow via props.children */ }
<td>{ props.children }</td>
<td>{education.degree}</td>
<td>
<Moment format="YYYY/MM/DD">{education.from}</Moment> -
{education.to === null ? ' Now' : <Moment format=" YYYY/MM/DD">{education.to}</Moment> }
</td>
<td>
<Button
className='btn btn-danger'
text='Delete'
onClick={() => props.deleteEducation(education.id)} />
</td>
</tr>)
}
Usage
{ /* Example of how to use TableRow */ }
const educationList = props.education.map(edu => (
<React.Fragment>
{ /* Render a button in first <td> of table row */ }
<TableRow education={edu} deleteEducation={this.deleteEducation} >
<button>Example button row</button>
</TableRow>
{ /* Render another table row with string in first <td> of table row */ }
<TableRow education={edu} deleteEducation={this.deleteEducation} >
{ `Example string row` }
</TableRow>
</React.Fragment>))
Please note, the purpose of this usage example is to illustrate how <TableRow> can be used to render different types of content in the first <td> of your common table row structure and is not indicative of how you would actually make use this component in your code.
Hope this helps!
edu.type?