You're trying to export a default and declare a variable at the same time, which is invalid syntax.

Consider the following, since we know that you can declare multiple variables using only one instance of the keyword, var a, b, c; the export definition wouldn't make sense at all.

export default var a, b, c;

What would that mean? What would get exported?

Furthermore, using the export default syntax already creates a variable called default that needs to contain a value or reference.

Export the variable instead if you want to make it a constant.

const Todo = () => {};

export default Todo;

There is a thread about this on ESDiscuss

Answer from Henrik Andersson on Stack Overflow
Top answer
1 of 2
149

You're trying to export a default and declare a variable at the same time, which is invalid syntax.

Consider the following, since we know that you can declare multiple variables using only one instance of the keyword, var a, b, c; the export definition wouldn't make sense at all.

export default var a, b, c;

What would that mean? What would get exported?

Furthermore, using the export default syntax already creates a variable called default that needs to contain a value or reference.

Export the variable instead if you want to make it a constant.

const Todo = () => {};

export default Todo;

There is a thread about this on ESDiscuss

2 of 2
13

Arrow function default export:

import React from 'react';
const Body=()=>(
    <div>This is my body</div>
);
export default Body;

Arrow function Named exports:

  1. First Way
import React from 'react';

export const Body = () => (
    <div>This is my body</div>
);
  1. Second Way
import React from 'react';

const Body = () => {
    return <div>This is my body</div>
};

export {Body};

You can also use 1 default and multiple named exports in the same file check below examples:

Example 1:

import React from 'react';

const Body1 = () => {
    return <div>This is my body1</div>
};

const Body2 = () => {
    return <div>This is my body2</div>
};

export {Body1, Body2};
you can import by using below code.
import {Body1, Body2} from 'bodyComponentPath';

Example 2

import React from 'react';
const MainBody = () => {
    return <div>This is my MainBody</div>
};

const Body1 = () => {
    return <div>This is my body1</div>
};

const Body2 = () => {
    return <div>This is my body2</div>
};

export {Body1, Body2};
export default MainBody;
you can import by using below code.
import MainBody, {Body1, Body2} from 'bodyComponentPath';

/* use named export components inside the curly bracket only */

import MainBody, {Body1, Body2} from 'bodyComponentPath';

🌐
Medium
dpericich.medium.com › why-cant-you-export-arrow-function-components-as-default-exports-in-react-5afcb364f1e8
Why Can’t You Export Arrow Function Components as Default Exports in React? | by Daniel Pericich | Medium
January 30, 2024 - Because of this, when we define an arrow function, we create an anonymous function and assign the expression to a variable. When performing a default export for a variable, we create a reference to this variable by assigning its value to default.
Discussions

Is it possible to export Arrow functions in ES6/7?
You cannot name a default export. ... Save this answer. Show activity on this post. Is it possible to export Arrow functions in ES6/7? More on stackoverflow.com
🌐 stackoverflow.com
Directly exporting an (arrow) function prevents it from being named
When using the export const Var = () => console.log('stuff'), the result code prevents the function from using the name of the variable, because it directly uses export.Var = () => co... More on github.com
🌐 github.com
1
July 29, 2020
export default arrow function cannot be imported
@Shamim Since it is a default export you can import it with any name like import renderDetails from '/path/to/render'; ... P.S. ./ is for if both files a re in same namespace/folder. ... I like this approach when wanting to combine similar functions into one file such as validators or filters ... More on stackoverflow.com
🌐 stackoverflow.com
November 4, 2017
What scenario would I not use an Arrow function?
I’m not sure why everyone ditched functions in favor of everything being a declared variable with an anonymous function. I pretty much always use functions and only use arrow functions for callbacks. I don’t like using anonymous functions for things that aren’t actually anonymous. More on reddit.com
🌐 r/reactjs
163
97
February 24, 2023
🌐
GitHub
github.com › alephjs › aleph.js › issues › 21
Can't export an arrow function as default from a page · Issue #21 · alephjs/aleph.js
November 8, 2020 - The default syntax is export default function Home(){ // ... } but when I use an arrow function export default () => { // ... } I get a blank page with 400 - Module "undefined" should export a React Component as default However, it works...
Author   hazae41
🌐
DEV Community
dev.to › saiprakashr42 › assign-arrow-function-to-a-variable-before-exporting-as-module-default-import-no-anonymous-default-export-14ji
Assign arrow function to a variable before exporting as module default import/no-anonymous-default-export - DEV Community
December 13, 2020 - export default () => { ... }; Use like this: const fn = () => { ... }; export default fn; For further actions, you may consider blocking this person and/or reporting abuse · SAI PRAKASH · Follow · WebDEV · Location · Hyd · Work · student ...
🌐
GitHub
github.com › microsoft › TypeScript › issues › 39819
Directly exporting an (arrow) function prevents it from being named · Issue #39819 · microsoft/TypeScript
July 29, 2020 - "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Foo = void 0; const Foo = () => console.log('I am Foo'); exports.Foo = Foo; console.log('Foo name is', exports.Foo.name); //# sourceMappingURL=Foo.js.map · This outputs on node and the browser: Foo name is Foo · Actual behavior: The (arrow) functions that are exported don't get any naming on the browser/node (they remain anonymous).
Author   josejulio
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Functions › Arrow_functions
Arrow function expressions - JavaScript - MDN Web Docs
February 21, 2026 - For the purpose of formatting, you may put the line break after the arrow or use parentheses/braces around the function body, as shown below. You can also put line breaks between parameters. ... const func = (a, b, c) => 1; const func2 = (a, b, c) => ( 1 ); const func3 = (a, b, c) => { return 1; }; const func4 = ( a, b, c, ) => 1; Although the arrow in an arrow function is not an operator, arrow functions have special parsing rules that interact differently with operator precedence compared to regular functions.
Find elsewhere
🌐
Learning Never Ends
learningneverendstech.com › home › blog › arrow function & default export vs named export in react js
Arrow Function & Default Export VS Named Export In React JS - Learning Never Ends
July 11, 2022 - Arrow functions were introduced in ES6. ... import logo from './logo.svg'; import './App.css'; function App() { return ( <h1>Learning Never Ends</h1> ); } const App = () => <h1>Mohammad Adil</h1>; const App = (props) => { return ( <> <h1>{props.name}</h1> <h2>{props.age}</h2> </> ); } const App = (props) => <h1>{props.age}</h1>; const App = props => <h1>{props.age}</h1>; export default App;
🌐
DEV Community
dev.to › abidullah786 › mastering-javascript-shorthand-techniques-part-5-asyncawait-arrow-function-and-exports-and-imports-2pj1
Mastering JS Shorthand Techniques Part-5: Async/Await, Arrow Function, and Exports and Imports - DEV Community
August 14, 2023 - For single expression functions, you can use arrow functions with implicit return for more concise code. // Longhand const multiply = (a, b) => { return a * b; }; ... For modules with a single export, you can use default exports and imports for shorter syntax.
🌐
DEV Community
dev.to › tmenyhart › comment › 195kp
I think the solution would be: Unstead of: export default () => { ... ... - DEV Community
December 13, 2020 - export default () => { ... }; Use like this: const fn = () => { ... }; export default fn; For further actions, you may consider blocking this person and/or reporting abuse · We're a place where coders share, stay up-to-date and grow their careers.
🌐
Webdevtutor
webdevtutor.net › blog › typescript-export-default-arrow-function
Understanding TypeScript Export Default Arrow Function
When importing the module, you ... arrow function as the default export in TypeScript, you can simply define the function using the arrow function syntax and export it using the export default statement....
🌐
CopyProgramming
copyprogramming.com › howto › javascript-can-you-default-export-an-arrow-function
Is it possible to use an arrow function as the default export in JavaScript? - Javascript
May 15, 2023 - This practice encourages the usage of a single identifier for the default export at both its declaration and import sites. Grepability refers to the ease of finding information through the use of programming conventions that follow certain patterns. The command 'grep' is specifically designed for this purpose and helps in locating information based on the patterns specified. Module exports passing argument to a arrow function, You should rather import it as const post = require("./utilities/apiCalls") or export as module.exports = {post}.
🌐
GitHub
github.com › babel › babel › pull › 4524
Fix default export with arrows and function naming by danharper · Pull Request #4524 · babel/babel
Default arrow function exports, with transform-es2015-arrow-functions and transform-es2015-function-name (or, just the es2015 preset) results in loss of the default export.
Author   babel
🌐
Stack Overflow
stackoverflow.com › questions › 67640266 › export-default-with-arrow-functions
reactjs - Export default with arrow functions - Stack Overflow
Why does using an arrow function not work in this situation but using const does? Thanks! import React from "react"; import "./App.css"; App = () => { return ( <div> <h1>React form handling</h1> <form> <label> First name: <input type="text" /> </label> </form> </div> ); }; export default App;
🌐
The Web Dev
thewebdev.info › home › how to export arrow functions in javascript?
How to export arrow functions in JavaScript? - The Web Dev
April 26, 2022 - To export arrow functions in JavaScript, we can use export directly with arrow functions.
🌐
YouTube
youtube.com › coderdmitri
REACT: default export unnamed with an arrow function - YouTube
REACT: default export unnamed with an arrow functionrepo with code: https://github.com/dmitrisanzharov/cra-ts-rm-playground/blob/defaultExportExample/src/com...
Published   June 18, 2024
Views   18
🌐
Reddit
reddit.com › r/reactjs › why do so many developers declare and export components this way? (example inside)
r/reactjs on Reddit: Why do so many developers declare and export components this way? (example inside)
October 15, 2023 -

The vast majority of React projects I've seen declare and export components as follows:

const Timer = (props) => {
  // component code here
}

export default Timer;

Even newly created default React project uses this in App.jsx file.

On one of the project I worked on it was prohibited to use default exports even for components. So we had:

export const Timer = (props) => {
  // code 
}

// and then import 
import { Timer } from './components/Timer"

The guy who created the style guide for the project believed that default exports are bad. But importing Timer from Timer is so stupid, isn't it? And it was not the only project I've seen using this kind of exporting components.

But my question is why I almost never see anyone using this:

export default function Timer(props) {
  // code
}

In my opinion it's much better than 2 previous options. It's short. It's clear. Maybe there are some cons I don't see?