Reputation: 1
I am using react-native-config for setting environment variable in my react native project. I have a local image url in my .env
config file. I am able to get the local image url in my component using Config.LOGO_URL
. Code snippets of files are following:
Environment config file i.e .env
LOGO_URL='logo.png'
I am using the LOGO_URL
in the component as below:
import Config from 'react-native-config';
render() {
<View>
<Image source={require(`../../assets/images/${Config.LOGO_URL}`)} />
</View>
}
When I am trying to use config variable Config.LOGO_URL
in Image source
I am getting error invalid call in require()
. However, hardcoded path to image source is working as expected.
Am I missing something? Thanks! in advance.
Upvotes: 0
Views: 844
Reputation: 16334
The problem is not with Config its with the way that you are accessing the images in runtime, as its a static resource you will have to require it beforehand and the use something like a switch to change your logo. More info in the below answer on requiring images. React Native - Image Require Module using Dynamic Names
Upvotes: 1