How can I import a JS file with special characters in it's name in React and JSX?
I can
import { tomorrow} from 'react-syntax-highlighter/dist/esm/styles/hljs';
(the folder contains tomorrow.js and tomrorrow-night.js)
but I can't:
import { tomorrow-night} from 'react-syntax-highlighter/dist/esm/styles/hljs';
I don't think destructuring works here because it's an import statement.
CodePudding user response:
you can try as
import * as Highlighter from 'react-syntax-highlighter/dist/esm/styles/hljs';
const TomorrowNight = Highlighter[`tomorrow-night`];
CodePudding user response:
How about using the import * as blah
import? That gives you an object that you can then lookup any string in.
import * as tmrw from from 'react-syntax-highlighter/dist/esm/styles/hljs';
const tmrw_night = tmrw['tomorrow-height']