Export import in reactjs

Question

Say I have class Panels and class Panel in my ui. I want to avoid multiple statements such as import Panel.. and import Panels ... every time I decide to use them.

Instead, I want to re-export Panel from Panels once, and in my app just say something like import * from 'Panels.js' causing both Panel and Panels appear in the scope of my App.

Is this possible? Good tutorial on the subject? thanks.


Show source
| javascript   | reactjs   2017-08-17 23:08 2 Answers

Answers to Export import in reactjs ( 2 )

  1. 2017-08-17 23:08

    You can use import * as Panels from 'Panels';

    Inside your code you should use Panels.Panel and Panels.Panels

    Don't forget that you need to export both in order to import them

  2. 2017-08-17 23:08

    You can import several things from the same module like so:

    import { Thing1 , Thing2 } from "module-name";
    

    Or import everything like so:

    import * as everything from "module-name";
    

    For all other variations see: https://developer.mozilla.org/sv-SE/docs/Web/JavaScript/Reference/Statements/import

Leave a reply to - Export import in reactjs

◀ Go back