My apologies for the confusing wording of the question. Basically when I call state from here:
this.state = {
newdiscoverPlanet: [
'sunp',
'twop',
'bluep',
'purplep',
'bluepurplep',
'redp',
'orangep'
],
};
_getRandomPlanet(){
var planetItem = this.state.newdiscoverPlanet[Math.floor(Math.random()*this.state.newdiscoverPlanet.length)];
this.setState({
currentPlanet: planetItem,
});
}
How do I get a different result from the same state?
<Text>{this.state.currentPlanet}</Text>
<Text>{this.state.currentPlanet}</Text>
<Text>{this.state.currentPlanet}</Text>
I know I could just add two more different states with all the items of newdiscoverPlanet
but 1) I have a chance of getting the same results 2) It seems too lengthy for something that might have an easier solution.
Aucun commentaire:
Enregistrer un commentaire