0

I have this function in a javascript-file:

//utils/commons.js

export function funcName() {
    return 1;
}

In a component I refer to it this way:

import React from 'react';
const funcName  = import('../../utils/commons');

const MyComponent = () => {
    let res = funcName();
    console.log('res:',res);

    return(
        <> 
        <div>
            hello
        </div>   
    )};
export default MyComponent;

This seems to be the right way when googling this matter. However, in the console I see:

Uncaught TypeError: funcName is not a function        

If I would write a console.log inside the common.js-file (somewhere outside the function) then it is printed. So the file is getting included. But the function is not recognized for some reason.

1 Answer 1

1

You can try to edit this :

const funcName  = import('../../utils/commons');

to this :

import { funcName } from '../../utils/commons';
Sign up to request clarification or add additional context in comments.

1 Comment

it does thank you, will accept it as soon as they let me do it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.