Skip to content
Advertisement

Export a function from a JavaScript file

I am trying to make a component in React that is just a function

JavaScript

I am importing my function in another component like this

JavaScript

but I get an error saying:

JavaScript

How do I export a js file that is just a function?

Advertisement

Answer

Since you export it as default you have to import it like so:

JavaScript

Edit: Another issue with your code is that the following is not syntactically correct.

JavaScript

Try this instead:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement