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?
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With