1

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)]
    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>
            })}

Jen
  • 21
  • 2
  • How about shuffling the array and then going through them one by one? https://stackoverflow.com/a/12646864/5708566 – windowsill Nov 10 '20 at 22:33
  • Where is ArrayExample defined? – RowanX Nov 10 '20 at 22:42
  • Is a simple array full of picture URLs I tried shuffling it but I don't want to display the full array just as many items as times the condition is true – Jen Nov 13 '20 at 18:19

0 Answers0