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

Commit

Permalink
Hook up delete button to remove contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
tylermcginnis committed Mar 2, 2018
1 parent d3d6eee commit 4b65612
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,20 @@ class App extends Component {
},
]
}
removeContact = (contact) => {
this.setState((currentState) => ({
contacts: currentState.contacts.filter((c) => {
return c.id !== contact.id
})
}))
}
render() {
return (
<div>
<ListContacts contacts={this.state.contacts} />
<ListContacts
contacts={this.state.contacts}
onDeleteContact={this.removeContact}
/>
</div>
)
}
Expand Down
6 changes: 4 additions & 2 deletions src/ListContacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ function ListContacts (props) {
<p>{contact.name}</p>
<p>{contact.handle}</p>
</div>
<button className='contact-remove'>
Remove
<button
onClick={() => props.onDeleteContact(contact)}

This comment has been minimized.

Copy link
@samehaladli

samehaladli Nov 19, 2021

It should be this.props.onDeleteContact, "this" is missing!

This comment has been minimized.

Copy link
@mohamedhadia

mohamedhadia Dec 7, 2021

it's a function component so you don't need 'this'

className='contact-remove'>
Remove
</button>
</li>
))}
Expand Down

0 comments on commit 4b65612

Please sign in to comment.