deejay123
deejay123

Reputation: 89

How to import an default exported object containing functions?

If one file has an export default:

export default {
   function,
   function2
}

How can I import these two functions in a separate file? When I try restructuring it with

import { function, function2 } from 'path'

I get an error saying function is not exported from 'path'

Upvotes: 0

Views: 41

Answers (2)

Milind Agrawal
Milind Agrawal

Reputation: 2944

Since it's a default export, you will have to do it like below

export default {
   function1,
   function2
}

import Path from 'path';

Path.function1();
Path.function2();

Upvotes: 1

Keimeno
Keimeno

Reputation: 2644

Look into this ressource.

Basically, you can achieve this, by writing:

export const myExport1 = function
export const myExport2 = function2

And then:

import { myExport1, myExport2} from 'path'

Upvotes: 0

Related Questions