Re-export default in ES 6 modules

后端 未结 3 1620
独厮守ぢ
独厮守ぢ 2020-12-13 05:14

In ES6, is it possible to shorten the following code. I have an App.js file and an index.js.

index.js

impo         


        
3条回答
  •  青春惊慌失措
    2020-12-13 06:17

    This is a bit of repetition from the previous answers, but to clarify the difference in two options:

    1. default export

    (This appears to be what OP wants)

    export { default } from './App'
    
    // in a different file
    import App from './index'
    

    2. named export

    export { default as App } from './App'
    
    // in another file
    import { App } from './index'
    

    These will work with react as vsync's answer states.

提交回复
热议问题