显示来自阵列的随机图像,无需重复

时间:2020-11-10 22:19:27

标签: image react-native random

我对React Native不太了解,我希望有人可以帮助我解决这个问题。如果条件为真,并且不重复已显示的相同图像,我将尝试显示来自数组的随机图片。我也尝试了.splice,但是对我没有用。

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

0 个答案:

没有答案