Search code examples
javascriptreactjsecmascript-5

How to organise exported components from own React library


I have been developing a library of components which I can reuse in my React projects. How can I export these components in groups of related functionality so that the corresponding import statement, of the project where my library is used, looks like the following?

import { Select1, Select2 } from 'myLib/Selects';
import { Button1, Button2 } from 'myLib/Buttons';
import { List1, List2 } from 'myLib/Lists';

Solution

  • // Selects.js
    export {
      Select1,
      Select2
    }
    
    // Buttons.js
    export {
      Button1,
      Button2
    }
    
    // Lists.js
    export {
      List1,
      List2
    }