Search code examples
javascriptreactjsjsxreact-syntax-highlighter

How can I import a JS file with special characters in it's name in React and JSX?


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.


Solution

  • you can try as

    import * as Highlighter from 'react-syntax-highlighter/dist/esm/styles/hljs';
    
    const TomorrowNight = Highlighter[`tomorrow-night`];