I have a list of results where each result has the following data: id, title, system, unit. This data is in the form of an object, e.g: ({id:1, title: "main engine", system: "ship", unit: "C"}).
Each result has an onclick that calls a my addFunc function that is a state. This looks like this:
class Search extends Component {
constructor(props) {
super(props);
this.addFunc = this.addFunc.bind(this);
this.state = { selectedData:[] }
}
addFunc(resultdata) {
var joined = this.state.selectedData.concat(resultdata);
this.setState({ selectedData: joined })
console.log(joined)
}
Currently, each object is added to my joined array when clicked, and I can see it in my console.
I want to display this on the screen
render()method, have you tried this?{this.state.selectedData}in myrender()method, but this causes an error because myselectedDatais an array of objects. for example, [{id:1, title: 'title'}, {id:2, title: 'hello'}]. How can I display this kind of data?