Home > Blockchain >  How to import Javascript functions from separate file into react component
How to import Javascript functions from separate file into react component

Time:04-19

I'm trying to import javascript functions into my react app but i'm getting this error:

Attempted import error: 'logGreeting' is not exported from './GreetingHelper'

Here is what my code looks like:

//React typescript file
import { logGreeting } from './GreetingHelper'

    ...
    logGreeting("hi")


//Javascript helper file
export const logGreeting = function (greeting) {
   console.log(greeting)
}

CodePudding user response:

It should look like that: export function logGreeting(greeting) { ...

CodePudding user response:

Changing the file type from .js to .jsx fixed the error.

GreetingHelper.js => GreetingHelper.jsx

  • Related