Reexporting from Another Module

Learn how named and default exports are reexported with the help of examples.

Why should we re-export modules

You can re-export modules to reduce the number of imports and make dependencies transitive. Occasionally, you may want to make some references that are contained in other modules available to the users of your module.

Example

For example, let’s say we create a weather module but we want to expose functions from the temperature module we created previously and also another hypothetical pressure module.

The weather module, itself, may expose some references that it contains. Now, suppose a module wants to use the references in the weather, temperature, and pressure modules. That user does not need three imports. Instead, by importing the weather module, thanks to reexport, the user will have access to references exported by all the three modules: weather, temperature, and pressure.

Get hands-on with 1400+ tech skills courses.