Import Modules for Side Effects
We’re not making any local assignments.
We aren’t importing functions or constants for later use.
We’re simply importing the global effects of the module, as if the code lived in this file.
On the module side, simply write code with effects.
We can load modules with side effects conditionally, with an immediately invoked async function.
Here, you can imagine checking an environment variable before importing side effects.
Modules can contain a mix of exports and effects.
While there may be a good reason to do this, it also make your imports unpredictable.
Here’s why I recommend avoiding the mix:
Module effects always run at import.
In a mixed module, you can import only the effects but you can not import only the exports.
I see this style of import used with Webpack to import stylesheets.
This is part of a course I’m build on modules at lunch.dev.
When live, members get access to this and other courses on React.