I am using brace which is a npm module for theming in ace editor. Currently, I am importing each theme using
import 'brace/theme/solarized_dark';
How do I import all the themes as I need to give the user the option to pick any theme.
In React we use the keyword import and from to import a particular module or a named parameter.
To conditionally import an ES6 module with JavaScript, we can use the import function. const myModule = await import(moduleName); in an async function to call import with the moduleName string to import the module named moduleName . And then we get the module returned by the promise returned by import with await .
Since we have a default export, importing anything from that file will provide us with a person object. For imports from the info. js file, we will import from two different constants. Therefore, we use {} to precisely target specific things from that file.
Create one brace/themes/index.js
and export the things that you want to acess
export * as theme1 from './theme1';
export * as theme2 from './theme2';
....
Then import from that folder : (name is index.js so no need to give full path to the file)
import * as SolDark 'brace/themes'; // by default get index.js
Then you can access each method like :
SolDark.theme1;
SolDark.theme2;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With