Uncaught Error: Objects are not valid as a React child (found: object with keys {titlesCollection}). If you meant to render a collection of children, use an array instead
I am getting this error while trying to render array of object, what I am doing wrong here?
import * as React from 'react';
import * as FontAwesomeIcon from 'react-fontawesome';
const data = {
otherTitles:[
{
titleHeading:"X",
titles:["A","B","C","D"]
},
{
titleHeading:"Y Z",
titles:["E","F","G","H"]
}
]
}
export class OtherTitlesCollection extends React.Component{
render() {
const titlesCollection = data.otherTitles.map((othertitle)=>{
let dataId = othertitle.titleHeading.replace(' ','');
return(
<div key={dataId}>
<div>
<FontAwesomeIcon name='plus-circle' data-toggle="collapse"
data-target={"#"+dataId} role="button" aria-expanded="false" aria-controls={dataId}/>
<label>{othertitle.titleHeading}</label>
</div>
<div className="collapse" id ={dataId}>
{
othertitle.titles.map((title)=>{
return(<div key={title} style={{margin: "1px auto 1px 10px"}}>{title}</div>);
})
}
</div>
</div>
)
});
return (
{titlesCollection}
);
}
};