1

I tried using the spread operator in one of my js files but I got an error. This is what my webpack config file looks like i.e. only the module section.

module: {
        loaders: [
          {
              test: /\.jsx?$/,
              exclude: /(node_modules|bower_components)/,
              loader: 'babel',
              query: {
                  presets: ['react', 'es2015']
              }
          }
        ]
    }

I assume, I had an issue because spread is still in proposal stage. What do I need to do so that I can use the spread operator in my project?

UPDATE: Here's how I was using it:

import * as actions1 from './someActions';
import * as actions2 from './moreActions';

export {
   ...actions1,
   ...actions2
};

This is the error message: enter image description here

Sam
  • 26,817
  • 58
  • 206
  • 383

1 Answers1

1

The other answer is correct for generic objects, but for the code you posted the answer is that you cannot take all the props of an object and export then as named exports. All of the names of an export must be knowable without executing the code of the module.

import * as actions1 from './someActions';
export {...actions1};

is not possible. You can however do

export * from './someActions';

to take all of the named exports from someActions (excluding default) and re-export then as named exports from your root file.

loganfsmyth
  • 156,129
  • 30
  • 331
  • 251