3

I have a function in a .react.js file that works fine in that file that imports as undefined in a different file.

So in in file1.react.js:

const functionName= function (): React.Node {
  return (
    <// insret code here>
  );
};

export default functionName;

and in file2.react.js:

import {functionName} from 'file1.react'

But when I try to call {functionName()} it says functionName isn't a function and when I do {typeof functionName} it says it's undefined.

FYI: I referenced question 43262599 and 54199264 when trying to get this to work.

anon_guest
  • 33
  • 3
  • 1
    Either change your export to say `export functionName` or change the import to `import functionName from 'file1.react'` – goto Jan 26 '21 at 00:00
  • 1
    try to look here: [https://stackoverflow.com/a/44309439/5427820](https://stackoverflow.com/a/44309439/5427820), but you can try to export directly your function by doing that: `export const functionName = () => ( // your jsx );` and after that use `import {functionName} from 'file1.react'` – Kidas Jan 26 '21 at 00:01
  • 1
    In addition to the named vs default export problem, if your import statement is actually ...`from 'file1.react'`, you'll need to add the relative path — imports without paths are for globals and node modules. – Zac Anger Jan 26 '21 at 03:35

1 Answers1

2

I guess this pictures is self-explanatory and will help you to know where you are going wrong

enter image description here

mss
  • 1,423
  • 2
  • 9
  • 18