In my react native app, I currently have the following import:
import { IMG_ARABIC_FLAG, IMG_ENGLISH_FLAG } from '../assets/images/index';
If I have a dynamic string, say 'IMG_ARABIC_FLAG', is there a way to do something like eval('IMG_ARABIC_FLAG') to import the flag from the /index module instead?
The list of languages is stored in an external JSON file, and the image constant is a resource containing the actual image. Because I am getting the flag name as string, I need a way to include the flag image using the string value.
const flags = new Map([['IMG_ARABIC_FLAG', IMG_ARABIC_FLAG], ['IMG_ENGLISH_FLAG', IMG_ENGLISH_FLAG], …]). The repetition is unfortunate, but kind of necessary.* from '../assets/images/flags'instead?