mardi 10 novembre 2020

Display random image from array without repeat

I am not very experienced with React Native, I would like someone could help me with this issue. I'm trying to display random pictures from an array if the condition is true and without repeating the same image already displayed. I tryied also with .splice but it didn't work for me.

const Example= () => {

  const [Nrandom, setNrandom] = useState([)
 
 const selected = () => {


    const find = ArrayExample[Math.floor(Math.random() * ArrayExample.length)].img
    if(Nrandom.filter((i => i !== find))){
          setNrandom(Nrandom => [...Nrandom, find])
      return find}

     }


return (
    <View style={styles.container}>
      <View>
        <View style={styles.background}>
          <View>
            {data.number.map((n) => {
              if (20 < n > 28)
                return <View style={styles.card}>
                  <View style={styles.card}>
                    <Image style={styles.clothes} source={selected()}></Image>
                  </View>

                </View>
            })}




Aucun commentaire:

Enregistrer un commentaire