React-native failed propType on Image component

前端 未结 2 1646
广开言路
广开言路 2020-12-24 05:20

I am just starting out with React-native and have a pretty decent grasp on React for creating web apps... I am running into a confusing issue here that never occured when wo

相关标签:
2条回答
  • 2020-12-24 05:45

    you should be use uri for set source image

    return (
      <Image 
        source={{uri: 'https://reactnative.dev/docs/assets/p_cat2.png'}}
      />
    );

    0 讨论(0)
  • 2020-12-24 05:55

    You should either require the local assets or use object with uri key.

    So either in MainComponent:

    this.state = {
      images:[
        require('./src/images/1.png'),
        require('./src/images/2.png'),
        require('./src/images/3.png')
      ]
    }
    

    or in BasicComponent:

    return (
      <Image 
        source={{uri: this.props.source}}
      />
    );
    
    0 讨论(0)
提交回复
热议问题