Multiple React components in a single module

后端 未结 4 1946
悲&欢浪女
悲&欢浪女 2020-12-08 21:43

I am new to the whole browserify thing. I have been trying to use browserify + reactify + gulp to transform, minify and combine a React application. As long as I have a sing

4条回答
  •  生来不讨喜
    2020-12-08 22:13

    You can do like this, with an index.js file into your /components/ folder

    /components/index.js

    import Users from './Users/Users';
    import User from './Users/User';
    
    
    module.exports = {
      User,
      Users
    }
    

    IMPORT

    import { Users, User } from './components';
    

    As you can see, I named my file index.js, it prevent me from write it in the import declaration. If you want to name your file with another name than index.js, you'd have to write the name of the file in the import, Node won't guess it ! ^^

提交回复
热议问题