Rajan Twanabashu
Rajan Twanabashu

Reputation: 4746

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

Upvotes: 3

Views: 1299

Answers (1)

liu pluto
liu pluto

Reputation: 324

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

Upvotes: 1

Related Questions