Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

local image not loading in <Image> react native

First I tried to load image with following code and it does load the image

render(){
return(
  <View style={{backgroundColor:'red', flex:1, alignItems:'center'}}>
    <Text> Landing Page controller</Text>
    <Image
    source={require('./symbol.png')}
  />
  </View>
);  }

enter image description here Now i have load lots of image through out the application from different files. In such case it is very difficult to maintain the code and resources. That's why I created the separate file

resource.js

 module.export= {
                symbol:require('./symbol.png'),
              };

and then in component file I tried to load like below.

import JResource from './resource.js';
   .....................
   ..................
 render(){
        return(
          <View style={{backgroundColor:'red', flex:1, alignItems:'center'}}>
            <Text> Landing Page controller</Text>
            <Image
            source={JResource.symbol}
          />
          </View>
        );
      }

Now the application did run , but no image is displayed. It would be great if any body would figure out what's wrong here.

enter image description here

like image 951
Rajan Twanabashu Avatar asked Feb 23 '26 08:02

Rajan Twanabashu


1 Answers

you should module.exports = ..... not export

like image 78
liu pluto Avatar answered Feb 25 '26 21:02

liu pluto