Skip to content

Instantly share code, notes, and snippets.

@apalmer0
Last active April 25, 2018 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apalmer0/8b607c9169ef0c5a8e30ec29744cfb46 to your computer and use it in GitHub Desktop.
Save apalmer0/8b607c9169ef0c5a8e30ec29744cfb46 to your computer and use it in GitHub Desktop.
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