There is a table, in which the product groups are rendered:
When clicking on a line, several more lines should be added to it (the group is expanded), like this:
(when clicking on the blue line, 2 more red lines were rendered)
I try to do it like this:
import React from "react"; class App extends React.Component { renderGroups(groups) { return groups.map(({ group: { name } }, index) => ( <tr key={index} className="group" onClick={this.onGroupToggle}> <td>{name}</td> <td>g-1.1</td> <td>g-1.2</td> <td>g-1.3</td> <td>g-1.4</td> <td>g-1.5</td> </tr> )); } renderProducts(products) { return products.map(({ name }) => ( <tr key={index} className="product"> <td>{name}</td> <td>g-1.1</td> <td>g-1.2</td> <td>g-1.3</td> <td>g-1.4</td> <td>g-1.5</td> </tr> )); } onGroupToggle() { console.log("onGroupToggle"); // какие то непонятные действия // которые должны привести к инжекту tr.product после tr.group } render() { const groups = [ { group: { group_id: 1, name: 'Телефоны' }, products: [ { product_id: 1, name: 'iPhone 7' }, { product_id: 1, name: 'iPhone 7 Plus' } ] } ]; return ( <table border="1"> <thead> <tr> <th>name</th> <th>1</th> <th>2</th> <th>3</th> <th>4</th> <th>5</th> </tr> </thead> <tbody> {this.renderGroups(groups)} </tbody> </table> ); } } App.propTypes = { example: React.PropTypes.object }; export default App; How to implement it correctly on React, because I can’t return 2 tr inside renderGroups.
renderProducts(products) { return products.map(({ name }) => ( <tr key={index} className="group"> <td>{name}</td> <td>g-1.1</td> <td>g-1.2</td> <td>g-1.3</td> <td>g-1.4</td> <td>g-1.5</td> </tr> <tr key={index} className="product"> <td>{name}</td> <td>g-1.1</td> <td>g-1.2</td> <td>g-1.3</td> <td>g-1.4</td> <td>g-1.5</td> </tr> <tr key={index} className="product"> <td>{name}</td> <td>g-1.1</td> <td>g-1.2</td> <td>g-1.3</td> <td>g-1.4</td> <td>g-1.5</td> </tr> )); } How to do it right?
UPDATE
Example: there is a Tables component which accepts TableRows components as props which renders all rows in the table (inside this component I wrap a string with the name of the group and product lines in tbody) but if this component returns several "tbody" feedl returns an error
TableRows.render (): A valid ReactComponent must be returned. You may have returned an undefined object.

