puddlejumper26 / blogs

Personal Tech Blogs
4 stars 1 forks source link

08 import { } with as && export default #37

Open puddlejumper26 opened 4 years ago

puddlejumper26 commented 4 years ago

Assume we have an exported component

function targetFunction() { }

export (targetFunction)

When we need to import a function from another class, normall is like this

import { targetFunciton } from '../targetClass';

// call this imported function
targetFunction();

And for the better understanding, actually we could also use the following method,

import { targetFunction as get } from '../targetClass';

//call this imported function
get();

but it seems it is not used very often.

And we could also use export default as following

function targetFunction() { }

export default targetFunction;

export default could only be used once for one component. then for the import part we need to modify as following

import targetFunction from  '../targetClass';