You can have only one default export which you declare like:

export default App; or export default class App extends React.Component {...

and later do import App from './App'

If you want to export something more you can use named exports which you declare without default keyword like:

export {
  About,
  Contact,
}

or:

export About;
export Contact;

or:

export const About = class About extends React.Component {....
export const Contact = () => (<div> ... </div>);

and later you import them like:

import App, { About, Contact } from './App';

EDIT:

There is a mistake in the tutorial as it is not possible to make 3 default exports in the same main.js file. Other than that why export anything if it is no used outside the file?. Correct main.js :

import React from 'react';
import ReactDOM from 'react-dom';
import { Router, Route, Link, browserHistory, IndexRoute  } from 'react-router'

class App extends React.Component {
...
}

class Home extends React.Component {
...
}


class About extends React.Component {
...
}


class Contact extends React.Component {
...
}


ReactDOM.render((
   <Router history = {browserHistory}>
      <Route path = "/" component = {App}>
         <IndexRoute component = {Home} />
         <Route path = "home" component = {Home} />
         <Route path = "about" component = {About} />
         <Route path = "contact" component = {Contact} />
      </Route>
   </Router>

), document.getElementById('app'))

EDIT2:

another thing is that this tutorial is based on react-router-V3 which has different api than v4.

Answer from Tomasz Mularczyk on Stack Overflow
๐ŸŒ
DhiWise
dhiwise.com โ€บ post โ€บ the-ultimate-guide-to-react-export-multiple-functions
React Export Multiple Functions
October 22, 2024 - The limitation of a default export is that a file can have only one default export. This means that if you have multiple values to export, you'll need to use named exports for the additional values.
๐ŸŒ
React
react.dev โ€บ learn โ€บ importing-and-exporting-components
Importing and Exporting Components โ€“ React
Export your function component from that file (using either default or named exports).
Discussions

reactjs - exporting multiple modules in react.js - Stack Overflow
note that when you use any of the non-default functions you must use it with its same spelling and liter case as in the export statement and also you must use it as a function like this: ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... 6 React - How to Export Multiple ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to use multiple `export default ` in react
You can't have multiple default exports, but you can have multiple (non-default) exports. Try adding export before the function keywords, like export function BlogDescription() { More on stackoverflow.com
๐ŸŒ stackoverflow.com
reactjs - ES6 how to do multiple default exports - Stack Overflow
I am still getting a hang of react+redux, and ES6. I am trying to implement socketio, and I come across the problem of having to export socketio connect with my redux's connect. redux connect exp... More on stackoverflow.com
๐ŸŒ stackoverflow.com
exporting multiple functions but always run default function first
Sorry for the bad description but I would like to create a "service.js" -file where I export multiple functions that retrieve data from a database. something like: ... import Person from ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
People also ask

What are the different ways to export multiple functions in React?
You can export multiple functions using named exports or default exports.
๐ŸŒ
dhiwise.com
dhiwise.com โ€บ post โ€บ the-ultimate-guide-to-react-export-multiple-functions
React Export Multiple Functions
What are some best practices for exporting multiple functions in React?
- Use descriptive names for your functions. - Group related functions together in the same file. - Avoid exporting too many functions from a single file. - Consider using named exports for clarity and reusability.
๐ŸŒ
dhiwise.com
dhiwise.com โ€บ post โ€บ the-ultimate-guide-to-react-export-multiple-functions
React Export Multiple Functions
Why is it beneficial to export multiple functions from a single file in React?
Exporting multiple functions promotes code organization, reusability, and maintainability. It allows you to break down your code into smaller, more manageable units and share them across different components.
๐ŸŒ
dhiwise.com
dhiwise.com โ€บ post โ€บ the-ultimate-guide-to-react-export-multiple-functions
React Export Multiple Functions
๐ŸŒ
Bobby Hadz
bobbyhadz.com โ€บ blog โ€บ react-export-multiple-functions
Export multiple Functions or Components from file in React | bobbyhadz
April 7, 2024 - Use named exports to export multiple functions in React, e.g. `export function A() {}` and `export function B() {}`.
Top answer
1 of 5
206

You can have only one default export which you declare like:

export default App; or export default class App extends React.Component {...

and later do import App from './App'

If you want to export something more you can use named exports which you declare without default keyword like:

export {
  About,
  Contact,
}

or:

export About;
export Contact;

or:

export const About = class About extends React.Component {....
export const Contact = () => (<div> ... </div>);

and later you import them like:

import App, { About, Contact } from './App';

EDIT:

There is a mistake in the tutorial as it is not possible to make 3 default exports in the same main.js file. Other than that why export anything if it is no used outside the file?. Correct main.js :

import React from 'react';
import ReactDOM from 'react-dom';
import { Router, Route, Link, browserHistory, IndexRoute  } from 'react-router'

class App extends React.Component {
...
}

class Home extends React.Component {
...
}


class About extends React.Component {
...
}


class Contact extends React.Component {
...
}


ReactDOM.render((
   <Router history = {browserHistory}>
      <Route path = "/" component = {App}>
         <IndexRoute component = {Home} />
         <Route path = "home" component = {Home} />
         <Route path = "about" component = {About} />
         <Route path = "contact" component = {Contact} />
      </Route>
   </Router>

), document.getElementById('app'))

EDIT2:

another thing is that this tutorial is based on react-router-V3 which has different api than v4.

2 of 5
7

When you

import App from './App.jsx';

That means it will import whatever you export default. You can rename App class inside App.jsx to whatever you want as long as you export default it will work but you can only have one export default.

So you only need to export default App and you don't need to export the rest.

If you still want to export the rest of the components, you will need named export.

https://developer.mozilla.org/en/docs/web/javascript/reference/statements/export

๐ŸŒ
YouTube
youtube.com โ€บ javaatpoint
11- How to Export Multiple Function, Module and App in React - YouTube
How to Export Multiple Function, Module and App in React Role of Default Keyword in export Statement
Published ย  July 8, 2020
Views ย  144
๐ŸŒ
Tim Mousk
timmousk.com โ€บ blog โ€บ react-export-function
How To Export A Function In React? โ€“ Tim Mouskhelichvili
March 11, 2023 - A file can contain multiple named exports. One file can combine a default export with multiple named exports. When importing a default export, you can use any name you want. ... javascriptimport React from "react"; const Element = () => ...
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ reactjs โ€บ reactjs-importing-exporting
React Importing and Exporting Components - GeeksforGeeks
Use when exporting multiple functionalities or components from the same file. When you want consistency in import names. Useful for utility functions, constants, or multiple related components. Use Default Exports for Primary Components: If a file contains a main component, itโ€™s often a good idea to use default export.
Published ย  2 weeks ago
๐ŸŒ
Talent500
talent500.com โ€บ blog โ€บ different-ways-to-import-and-export-components-in-react-js
React JS Import and Export Explained: Guide with Examples
June 12, 2025 - That means they will be used later in other React components. We can have multiple Named exports in a React component, so we can use the curly braces { } to export more than one Named export instead of exporting individually.
๐ŸŒ
DEV Community
dev.to โ€บ jeetvora331 โ€บ different-types-of-export-in-react-21p8
Different Types of Export in React - DEV Community
September 13, 2023 - // Message.js import React from 'react'; const Message = () => { return <div>Hello React!</div>; } export default Message; You can import the Message component in another file like this: ... A file can have as many named exports as you like.
๐ŸŒ
Atomizedobjects
atomizedobjects.com โ€บ blog โ€บ javascript โ€บ how-to-export-multiple-functions-in-javascript
How to export multiple functions in JavaScript | Atomized Objects
August 27, 2021 - Discover how to export multiple functions in JavaScript as well as exporting multiple variables, named exports, and default exports.
๐ŸŒ
Solved
sharooq.com โ€บ solved-only-one-default-export-allowed-per-module
Solved - Only one default export allowed per module - Sharooq
May 4, 2022 - Read more posts by this author. ... The error is self-explanatory as it is. The error "Only one default export allowed per module" occurs on React when exporting more than one function as default.
๐ŸŒ
DhiWise
dhiwise.com โ€บ post โ€บ export-default-function-react-the-keystone-of-modular-code
The Power of Export Default Function in React
March 1, 2024 - You have two main options when exporting components in React: named exports and default exports. Each has its advantages and use cases. Named exports are useful when a module provides multiple functionalities that should be consumed separately.
๐ŸŒ
Debbie Codes
debbie.codes โ€บ blog โ€บ learning-react
Learning React ยท Debbie Codes
March 21, 2021 - There are 2 ways to export a component. Using named exports or default exports. With default export you can only have one function to export but with named exports you can have more than one.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 68574630
exporting multiple functions but always run default function first
Sorry for the bad description but I would like to create a "service.js" -file where I export multiple functions that retrieve data from a database. something like: ... import Person from '../models/Person' import dbConnect from "../lib/dbConnect"; await dbConnect() const save = async (person) => { const savedPerson = await Person.save(person) return savedPerson } const geAll = async () => { const persons = await Person.find({}) return persons } ... export default { getAll, save };
๐ŸŒ
YouTube
youtube.com โ€บ watch
Export, Import Functions, Classes, Components in React | Single File Multiple Components - YouTube
In React we create small reusable partials or components. Preferably single responsibility components. Then we import, export, mount, unmount these component...
Published ย  August 13, 2020
๐ŸŒ
DEV Community
dev.to โ€บ samyak112 โ€บ export-vs-export-default-in-js-2fbi
Export vs Export Default in JS - DEV Community
December 9, 2023 - The thing to notice here is that, here we can't change the name when importing those functions because it wasn't exported as a default. Also, you cant export multiple functions as default.
Top answer
1 of 7
506

Export like export default HelloWorld; and import, such as import React from 'react' are part of the ES6 modules system.

A module is a self contained unit that can expose assets to other modules using export, and acquire assets from other modules using import.

In your code:

import React from 'react'; // get the React object from the react module

class HelloWorld extends React.Component {
  render() {
    return <p>Hello, world!</p>;
  }
}

export default HelloWorld; // expose the HelloWorld component to other modules

In ES6 there are two kinds of exports:

Named exports - for example export function func() {} is a named export with the name of func. Named modules can be imported using import { exportName } from 'module';. In this case, the name of the import should be the same as the name of the export. To import the func in the example, you'll have to use import { func } from 'module';. There can be multiple named exports in one module.

Default export - is the value that will be imported from the module, if you use the simple import statement import X from 'module'. X is the name that will be given locally to the variable assigned to contain the value, and it doesn't have to be named like the origin export. There can be only one default export.

A module can contain both named exports and a default export, and they can be imported together using import defaultExport, { namedExport1, namedExport3, etc... } from 'module';.

2 of 7
66

export default is used to export a single class, function or primitive from a script file.

The export can also be written as

export default class HelloWorld extends React.Component {
  render() {
    return <p>Hello, world!</p>;
  }
}

You could also write this as a function component like

export default function HelloWorld() {
  return <p>Hello, world!</p>
}

This is used to import this function in another script file

import HelloWorld from './HelloWorld';

You don't necessarily import it as HelloWorld you can give it any name as it's a default export

A little about export

As the name says, it's used to export functions, objects, classes or expressions from script files or modules

Utiliites.js

export function cube(x) {
  return x * x * x;
}
export const foo = Math.PI + Math.SQRT2;

This can be imported and used as

App.js

import { cube, foo } from 'Utilities';
console.log(cube(3)); // 27
console.log(foo);    // 4.555806215962888

Or

import * as utilities from 'Utilities';
console.log(utilities.cube(3)); // 27
console.log(utilities.foo);    // 4.555806215962888

When export default is used, this is much simpler. Script files just exports one thing. cube.js

export default function cube(x) {
  return x * x * x;
};

and used as App.js

import Cube from 'cube';
console.log(Cube(3)); // 27
๐ŸŒ
DEV Community
dev.to โ€บ ayon_ssp โ€บ mastering-react-component-exports-a-comprehensive-guide-for-developers-2553
Mastering React Component Exports: A Comprehensive Guide for Developers - DEV Community
July 12, 2024 - // File: MyComponents.js export const AnotherComponent = () => { return <div>Another Component</div>; }; const MyComponent = () => { return <div>Hello World</div>; }; export default MyComponent; ... You can export functions, classes, or variables ...