Created
August 1, 2020 09:28
-
-
Save Vanns35/191671e666eeaf4e8389d7cc2bc171ce to your computer and use it in GitHub Desktop.
React Native Custom Multi Selector - Step 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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