I have a contact list with Edit button. When it's clicked I want to make the <div> with inputs to appear. Currently, when the button is clicked, this <div> is showing for all elements in my contact list.
Here's the code. I did not put here code which fetches contacts from API etc.
```
class App extends Component {
state = {
contacts: [],
firstName: '',
lastName: '',
phoneNumber: '',
email: '',
editVisible: true
};
showEditDiv = (id) => {
this.setState({
editVisible: !this.state.editVisible
})
};
render() {
const visibility = this.state.editVisible ? 'unvisible' : 'visible';
return (
<ul>
{this.state.contacts.map(contact => {
return (
<div>
<li key={contact.id}>
<p>{contact.firstName} {contact.lastName}</p>
<p>{contact.phoneNumber}</p>
<p>{contact.email}</p>
<button onClick={() => this.removeContact(contact.id)}>Remove</button>
<button onClick={() => this.showEditDiv(contact.id)}>Edit</button>
<div key={contact.id} className={`edit-form ${visibility}`}>
<p>This is edit form</p>
</div>
</li>
</div>
)
})}
</ul>
</div>
);
}
}
export default App;
.edit-form { height: 100px; background: #a7a7a7; } .unvisible { display: none; } .visible { display: block; }
</div>tag at the end of your render method - this may be causing you layout problems