I want to hide a particular element in react list.
This is how state looks like:
this.state = {
lgShow: false,
list: [
{ id:1, hidden: true },
{ id:2, hidden: true }
]
};
This is how component looks like:
props.list.map( result => (
<button onClick={toggle(result.id)}> Hide </button>
{ result.hidden && <div id={result.id}> .... </div> }
))
I want to write function toggle which searches the id in App.js and change value of hidden for that id, something like this(Although I'm not able to setState() in this case).
let toggle = id => {
this.state.list.filter( val=>val.id===id ? val.hidden=!val.hidden )
}