I have a list of todo items where I have to show the details of todo item on click of a button. I have two buttons "View Details" and "Hide Details" for the same.Below is code:
class Todos extends React.Component{
constructor(props){
super(props);
this.state={
shown:false,
todos: []
}
}
showDetails = (bool) => {
this.setState({
shown:bool
});
}
render(){
const { shown, todos } = this.state;
return(
<div>
<ul>
{todos.map((todo,i)=>(
<li key={todo.id}>
<span >{todo.title}</span>
<button onClick={this.showDetails.bind(this, true)}>View Details</button>
<button onClick={this.showDetails.bind(this, false)}>Hide Details</button>
{shown && (<div>
Description:{todo.description}<br/>
Due Date: {todo.status} <br/>
</div>) }
</li>
))}
</ul>
}
The issue here is that I will be having multiple view and hide buttons for each todo item and whenever I click on that button, details of all the todo items gets displayed. How can I click a todo item and able to see only that todo item's detailed view?
null
instead ofthis
?