Blog>
Snippets

Re-exporting modules

Demonstrate how one module can re-export modules it has imported, possibly under new names.
// moduleA.js
export const functionA = () => {
    console.log('Function A from module A');
};
This is moduleA.js where we define and export functionA.
// moduleB.js
export const functionB = () => {
    console.log('Function B from module B');
};
This is moduleB.js where we define and export functionB.
// reexporter.js

// Re-exporting functionA without renaming
export { functionA } from './moduleA.js';

// Re-exporting functionB with renaming it to renamedFunctionB
export { functionB as renamedFunctionB } from './moduleB.js';
This is reexporter.js where we re-export functionA directly and functionB under a new name, renamedFunctionB.