In file1.js:
const doSomething = () => {
console.log('yay');
};
export { doSomething };
//simplified, not using export default due to multiple exports
In file2.jsx:
import { doSomething } from './file1.js';
doSomething(); //undefined
Been trying to solve this for a while now. Trying to import this method from one class and add it as an onClick for a component, but it's always undefined. Help would be appreciated
edit1: fixed import in simplified code
You can try this. import file1.js in file2.js like this
import * as demo from './file1.js';
and call your function like this
demo.doSomething()
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