Reputation: 133
I'm using bellow babelrc setting.
{
"presets": ["es2015", "react"]
}
then, I when I use ...reducers I get unexpected token error. Do you know how to resolve it? I expected that cause is reducer setting. And If I add 'stage-1' on babelrc. it can resolve. But I don't want to add it. Please tell me it except for adding 'stage-1' on babelrc.
Thanks!
index.js
import React from 'react';
import ReactDOM from 'react-dom';
import { createStore, combineReducers, applyMiddleware, compose } from 'redux';
import { Provider } from 'react-redux';
import { Router, Route, IndexRoute, browserHistory } from 'react-router';
import { syncHistoryWithStore, routerReducer } from 'react-router-redux';
import thunk from 'redux-thunk';
import * as storage from './persistence/storage';
import randomToken from './utlis/random';
import getPastDays from './utlis/pastFutureDays';
import * as reducers from './reducers';
import {
App,
Home,
} from './components';
import style from './css/style.css';
const reducer = combineReducers({
...reducers,
routing: routerReducer,
});
./reducers/application.js
import { REGISTER_TOKEN } from '../constants';
const initialState = {
token: null,
createdAt: null,
};
export default function access(state = initialState, action) {
if (action.type === REGISTER_TOKEN) {
return { token: state.token };
}
return state;
}
./reducers/index.js
export { default as cityForecast } from './cityForecast';
export { default as application } from './application';
Upvotes: 1
Views: 360
Reputation: 2288
The object spread operator proposed for the next versions of JavaScript which lets you use the spread (...) operator to copy enumerable properties from one object to another in a more succinct way.
Unfortunately ES6 spread operator works only with arrays.
If you dont want to add babel preset for that, you can use Object.assign
instead.
So you can combine your reducers in the following way:
const reducer = combineReducers(
Object.assign(reducers, {routing: routerReducer})
);
You can find more info here https://googlechrome.github.io/samples/object-assign-es6/
Upvotes: 1