React-Native Image Invalid prop 'source' supplied to Image

前端 未结 2 864
春和景丽
春和景丽 2021-01-12 13:18

I think this is a very annoying bug and feels like there is no solution but I want to share and ask.. I fetch data from server and I get image source from there and I use sa

2条回答
  •  感情败类
    2021-01-12 14:18

    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:

    
    

提交回复
热议问题