Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

export default arrow function cannot be imported

I'm using React, and I have something like this in my code:

renderDetails.js:

export default renderDetails = (details) => {
    // function logic removed for brevity
}

Then, in the same folder, I have another source file from where I want to import it, and I do something like this:

businessDetails.js:

import renderDetails from './renderDetails';
// rest removed for brevity

But, I get an error message pointing to my renderDetails.js file and says: "rederDetails is not defined". Any ideas what the problem might be and how to fix it?

like image 973
typos Avatar asked Oct 04 '17 10:10

typos


People also ask

How to export arrow functions in JavaScript?

To export arrow functions in JavaScript, we can use export directly with arrow functions. to export the hello function as a default export with export default. to export hello as a named export. To export arrow functions in JavaScript, we can use export directly with arrow functions.

How do I export a variable as a default export?

IMPORTANT: If you are exporting a variable (or an arrow function) as a default export, you have to declare it on 1 line and export it on the next. You can't declare and default export a variable on the same line.

What is the difference between a default export and a named Import?

If a value is exported as a default export, it has to be imported as a default import and if it's exported as a named export, it has to be imported as a named import. Use the search field on my Home Page to filter through my more than 1,000 articles.

Does not contain a default export error in ES6?

To solve the "does not contain a default export" error, be consistent with your ES6 imports and exports. If a value is exported as a default export, it has to be imported as a default import and if it's exported as a named export, it has to be imported as a named import.


1 Answers

The problem is that even though you are exporting the component as default you are giving it a name which is not defined

You can either do

export default (details) => {

}

or

const renderDetails = (details) => {

}
export default renderDetails;

One more thing, when you are trying to render components, make sure that their name starts with a Uppercase character.

like image 195
Shubham Khatri Avatar answered Oct 12 '22 16:10

Shubham Khatri