Load image passed as props react native

前端 未结 7 1347
清歌不尽
清歌不尽 2021-01-04 20:02

When I am trying to load image from props i am getting the following error warning: failed prop type: invalid prop source supplied to image

7条回答
  •  醉梦人生
    2021-01-04 20:35

    As the React Native Documentation says, all your images sources needs to be loaded before compiling your bundle.

    Adding a simple image in React Native should be like this:

    
    

    Let's say you have this:

    const slides = {
      car: './car.png',
      phone: '../phone.png',
    }
    

    Then you pass slides as a parameter but still, you won't be able to use it like this (even though logically should work):

    
    

    Use require() inside the sildes{}

    const slides = {
      car: require('./car.png'),
      phone: require('../phone.png'),
    }
    

    And the use it like this:

    
    

提交回复
热议问题