Search code examples
javascriptreactjsrefluxjs

Import default with alias


I would like to import a default exported store with an alias using the syntax import XXX as A from YYY.

I know it works with this set up:

class XXX extends Reflux.Store{...}
export XXX;

//In another class you import:
import {XXX as ABC} from YYY;

That works great, but using that syntax with export default no longer works.

export default class XXX extends Reflux.Store{...}

//In another class you import:
import {XXX as ABC} from YYY;

But I know that if you export default you can't use {} syntax. Problem is that to use import as you need {}.

Any ideas?


Solution

  • All you need to do is import it with the name you want to use it with. There is no need to use the same name that was given to the module exported by default, you can use any name to import it

    import ABC from 'YYY'; // syntax for default import
    

    which is the short for

    import  { default as ABC } from 'YYY'