Skip to content

Instantly share code, notes, and snippets.

@Vanns35
Created August 1, 2020 09:28
Show Gist options
  • Save Vanns35/191671e666eeaf4e8389d7cc2bc171ce to your computer and use it in GitHub Desktop.
Save Vanns35/191671e666eeaf4e8389d7cc2bc171ce to your computer and use it in GitHub Desktop.
React Native Custom Multi Selector - Step 3
selectPokemon(item) {
if (!item.Choose) {
const newArray = [...this.state.PokemonList];
const replaceArray = {
id: item.id,
Name: item.Name,
Avatar: item.Avatar,
Choose: !item.Choose
};
newArray.splice(newArray.findIndex(ele => ele.id === item.id), 1, replaceArray);
this.setState({ PokemonList: newArray });
this.state.SelectedPokemon.push({
id: item.id,
Name: item.Name,
Avatar: item.Avatar
})
} else {
const newArray = [...this.state.PokemonList];
const replaceArray = {
id: item.id,
Name: item.Name,
Avatar: item.Avatar,
Choose: !item.Choose
};
newArray.splice(newArray.findIndex(ele => ele.id === item.id), 1, replaceArray);
this.setState({ PokemonList: newArray });
const deleteArrayValue = [...this.state.SelectedPokemon];
deleteArrayValue.splice(deleteArrayValue.findIndex(ele => ele === item.id), 1);
this.setState({ SelectedPokemon: deleteArrayValue });
}
}
onChoose() {
this.setState({
SavedPokemon : this.state.SelectedPokemon,
MultiSelectPopup: false
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment