Skip to content

Instantly share code, notes, and snippets.

@apalmer0
Last active Apr 25, 2018
Embed
What would you like to do?
class CityList extends Component {
state = {
cities: [
{
id: 1,
name: 'Boston',
},
{
id: 2,
name: 'Cambridge',
},
{
id: 3,
name: 'Somerville'
},
]
}
deleteCity = city => () => (
this.setState(prevState => ({
cities: prevState.cities.filter(({ name }) => name !== city.name),
}))
)
render() {
const { cities } = this.state
return (
<div>
{
cities.map((city) => (
<div key={city.id}>
<div onClick={this.deleteCity(city)}>X</div>
<City name={city.name} />
</div>
))
}
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment