I have multiple buttons that are rendered for multiple items. All the buttons have a unique id that I passed to the key, and I'm trying to disable the button based on the unique ID. The disable boolean is in the state, and when the button is clicked I want it to disable that one unique button.
However, the code I have disables all of the buttons that are rendered.
I've used map to access the parks items array in my state, so I'm not sure how I'd map over the buttons if I turned them into an array with unique keys in the state.
Here's what I have so far:
My state:
this.state = {
parks: [],
todos: [],
disabled: false
};
The button:
<button
key={item.id} //this id is coming from the mapped array "parks" state
disabled={this.state.disabled}
onClick={() =>
this.setState({
todos: [...this.state.todos, item.name], //this adds the parks
//state items to the todos
//state array
disabled: true
})
}
>