React 07: Import Export


include arbitrary code

import './bootstrap';

Includes a file without importing anything.

This will execute the target module without affecting the scope of the active module.

But it may have side-effects such as declaring globals or modifying existing globals.

https://stackoverflow.com/a/42252008/759452


import/export for utility functions

utilities.js

export function getNewExpirationTime() {
  return Date.now() + 15 * 1000;
}
export function generateId() {
  return 13423;
}

in other file


import/export for utility functions

CommentsData.js

in other file


import/export for CSS

TitleScreen.module.css

App.js


default vs named exports

You can export a function component from a file using either default or named exports.

Import must then be done using the relevant technique — different whether default or named exports.

Last updated