If you opt to convert this inside return() of the render method, the easiest option would be using the map( ) method. Map your array into JSX syntax using the map() function, as shown below (ES6 syntax is used).
Inside the parent component:
<tbody>
{ objectArray.map(object => <ObjectRow key={object.id} object={object.value} />) }
</tbody>
Please note the key
attribute is added to your child component. If you didn't provide a key attribute, you can see the following warning on your console.
Warning: Each child in an array or iterator should have a unique "key" prop.
Note: One common mistake people do is using index
as the key when iterating. Using index
of the element as a key is an antipattern, and you can read more about it here. In short, if it's not a static list, never use index
as the key.
Now at the ObjectRow component, you can access the object from its properties.
Inside the ObjectRow component
const { object } = this.props
Or
const object = this.props.object
This should fetch you the object you passed from the parent component to the variable object
in the ObjectRow component. Now you can spit out the values in that object according to your purpose.
References: