Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import everything from a module in react using es6?

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.

like image 581
uman Avatar asked Oct 24 '17 10:10

uman


People also ask

How do I import a module into React?

In React we use the keyword import and from to import a particular module or a named parameter.

How can I conditionally import an ES6 module?

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 .

What is import {} In React?

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.


1 Answers

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;
like image 133
Vivek Doshi Avatar answered Sep 28 '22 17:09

Vivek Doshi