Skip to content
This repository was archived by the owner on Jun 28, 2022. It is now read-only.

Commit 4b65612

Browse files
committed
Hook up delete button to remove contacts
1 parent d3d6eee commit 4b65612

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

src/App.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,20 @@ class App extends Component {
2424
},
2525
]
2626
}
27+
removeContact = (contact) => {
28+
this.setState((currentState) => ({
29+
contacts: currentState.contacts.filter((c) => {
30+
return c.id !== contact.id
31+
})
32+
}))
33+
}
2734
render() {
2835
return (
2936
<div>
30-
<ListContacts contacts={this.state.contacts} />
37+
<ListContacts
38+
contacts={this.state.contacts}
39+
onDeleteContact={this.removeContact}
40+
/>
3141
</div>
3242
)
3343
}

src/ListContacts.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ function ListContacts (props) {
1515
<p>{contact.name}</p>
1616
<p>{contact.handle}</p>
1717
</div>
18-
<button className='contact-remove'>
19-
Remove
18+
<button
19+
onClick={() => props.onDeleteContact(contact)}
20+
className='contact-remove'>
21+
Remove
2022
</button>
2123
</li>
2224
))}

0 commit comments

Comments
 (0)