Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import multiple things in javascript

I want to import multiple things in js, I have tried with import * like this:

the export file AppEpics.js:

export fooEpic = Observable.of() // some fancy code;
export barEpic = Observable.of() // some other fancy code;

the import file:

import * as App from './AppEpics'
export default combineEpics(...App)

I found that while I log the App, I get a object that contains the foo and bar, but when I log the ...App, I get nothing.

I am using babel preset env and react for now. How do I solve that?

BTW, the combineEpics only accepts the epics like fooEpics, so that I cannot call this function like this:

import * as App from './AppEpics'
export default combineEpics(App) // that will not work.
like image 506
leuction Avatar asked Nov 18 '25 09:11

leuction


1 Answers

The App is object in your case and you try to spread it as arguments for function combineEpics(...App) which would work only if App is array.

If you want to pass all the exported values into combineEpics you need to do smth like combineEpics(...Object.values(App)) or add export default [foo, bar] in App.js and import App from './App' and combineEpics(...App) in file.

like image 118
Sergii Vorobei Avatar answered Nov 20 '25 21:11

Sergii Vorobei



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!