Below is the code
require("index/components/" + name); //fails
require("index/components/myComponent"); //work fine
any good solution ?
Below is the code
require("index/components/" + name); //fails
require("index/components/myComponent"); //work fine
any good solution ?
Dynamic paths in require are not currently supported. Please check this answer
This is covered in the documentation under the section "Static Resources":
The only allowed way to refer to an image in the bundle is to literally write require('name-of-the-asset') in the source.
You can use a switch
statement to implement this.
I'm not sure about it but you can try to write it in ES6
require(`index/components/${name}`);