Here is my list:
newdiscoverPlanet: [
require('../img/sunp.png'),
require('../img/twopp.png'),
require('../img/bluep.png'),
require('../img/purplep.png'),
require('../img/bluepurplep.png'),
require('../img/redp.png'),
require('../img/orangep.png')
],
I put all of this into a function then use Math
here:
getRandomPlanet = () =>{
var planetItem = this.state.newdiscoverPlanet[Math.floor(Math.random()*this.state.newdiscoverPlanet.length)];
this.setState({
changePlanet: planetItem,
});
}
And then I put them into tabs to get a unique image from the list:
_renderTabIndicator() {
let tabs = [{
text: `${this.state.tags.toLowerCase()}`,
iconSource: `${this.state.changePlanet}`
},{
text: `${this.state.tags2.toLowerCase()}`,
iconSource: `${this.state.changePlanet}`
},{
text: `${this.state.tags3.toLowerCase()}`,
iconSource: `${this.state.changePlanet}`
}];
return <PagerTabIndicator tabs={tabs} />;
}
But everytime I load the page I get the same image from each source. Is there a way to make them unique? How can I do something like this in React Native: https://stackoverflow.com/a/2380113/9318643