Back to React Notes
Topic #14

ES6 Modules

ES modules let you split code across files and import only what you need. React components are shared this way, one file per component.


Modules

JavaScript modules allow you to break up your code into separate files.

This makes it easier to maintain the code-base.

ES Modules rely on the import and export statements.


Export

You can export a function or variable from any file.

Let us create a file named person.js, and fill it with the things we want to export.

There are two types of exports: Named and Default.


Named Exports

You can create named exports two ways:

Example

export const name = "Tobias"
export const age = 18

Example

const name = "Tobias"
const age = 18

export { name, age }

Default Exports

Let us create another file, named message.js, and use it for demonstrating default export.

You can only have one default export in a file.

Example

const message = () => {
  const name = "Tobias";
  const age = 18;
  return name + ' is ' + age + 'years old.';
};

export default message;

Import

You can import modules into a file in two ways, based on if they are named exports or default exports.

Named exports must be destructured using curly braces. Default exports do not.

Example

import { name, age } from "./person.js";

Example

import message from "./message.js";

Want to go beyond the notes?

Join Coding Now Tech Institute's React course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

ES6 Modules – FAQs

Quick answers about learning ES6 Modules in React.

This free note from Coding Now Tech Institute explains ES6 Modules in React — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every React topic on Coding Now Tech Institute, including ES6 Modules, is 100% free with no signup required.
With focused practice, most students grasp ES6 Modules in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now