here in react native , I am getting error while attempting this
<Image source={require(`../assets/${expand[0] ? 'expand':'expandDown'}.png`)} />
expand[0] is true/false
error name simply syntax error
here in react native , I am getting error while attempting this
<Image source={require(`../assets/${expand[0] ? 'expand':'expandDown'}.png`)} />
expand[0] is true/false
error name simply syntax error
You can’t use a template literal in a require statement, but I think something like this would work:
{expand[0]
? <Image source={require('../assets/expand.png')} />
: <Image source={require('../assets/expandDown.png')} />}
Thanks. this works
But i remember I did something similar in my last project and it worked there. Maybe it was something else, thanks again
I’d be interested if you find anything out, I’m just getting into React Native. From this link, it seems that dynamically requiring assets isn’t possible(?):
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.