Is it possible to do multiple class imports with ES6/Babel?

前端 未结 4 472
借酒劲吻你
借酒劲吻你 2020-12-28 13:10

I\'m working on a react project (my first) and I\'ve recently restructured my folder structure to make a bit more sense.

To make my life easier, within my component

相关标签:
4条回答
  • 2020-12-28 13:15

    You can export like this:

    import App from './App';
    import Home from './Home';
    import PageWrapper from './PageWrapper';
    
    export {
        App,
        Home,
        PageWrapper
    }
    

    Then, you can import like this wherever you need it:

    import { App, PageWrapper } from './index' //or similar filename
    
    ...
    

    You can read more about import and export here. I also answered a similar question here.

    0 讨论(0)
  • 2020-12-28 13:19

    I use export that looks something like this. In react it worked well

    export {default as PublicRoute} from './PublicRoute';
    export {default as PrivateRoute} from './PrivateRoute';
    

    Then, you can import like this wherever you need:

    import {PublicRoute, PrivateRoute} from './config/router';
    ...
    
    0 讨论(0)
  • 2020-12-28 13:30

    you can use this method

    import * React from 'react'
    
    0 讨论(0)
  • 2020-12-28 13:34

    One can have multiple named exports per file then import the specific exports by surrounding by braces. The name of the imported module has to be the same as the name of the exported module.

    import {Something, Somethingelse} from './utility.js'

    One can also import all exports as the following:

    import * as bundled from './utility.js'

    0 讨论(0)
提交回复
热议问题