I have 2 buttons and div info. In the state I have recorded an array within which the key and the component. When I click on one of the buttons, I want the component to be displayed in the info div. Where is the mistake?
import React, { Component } from 'react';
import Donald from '/.Donald';
import John from '/.John';
class Names extends Component {
state = {
array :[
{keys:1, name:<Donald/> },
{keys:2, name:<John/> }]
};
searchName = (keys)=>{
const arrr = this.state.array.filter(item => item.keys === keys);
this.setState({array : arrr})
return this.state.arrr;
}
searchInfo =()=>{
const cont = this.state.array.filter(item => item.name === this.state.name);
return cont;
}
render() {
return(
<div>
<div className="info">{this.searchInfo(this.state.name)}</div>
<div>
<button onClick={ () => this.searchName(1) }>My name Donald</button>
<button onClick={ () => this.searchName(2)}>My name John</button>
</div>
</div>
)
}
}
export default Names;