我正在尝试在我的减速器中使用传播属性,但是它又返回了无效的语法错误。我的构建支持使用散布运算符,因为我仅在我的减速器中得到错误。
auth_types.js
export const AUTH_USER = 'AUTH_USER' export const UNAUTH_USER = 'UNAUTH_USER'
auth_actions.js
import { AUTH_USER, UNAUTH_USER } from './auth_types' export function signinUser({ email, password }) { return function(dispatch) { axios.post(`${ROOT_URL}/signin`, { email, password }) .then(response => { dispatch({ type: AUTH_USER }) browserHistory.push('/feature') }) } }
reducer.js
import { AUTH_USER, UNAUTH_USER } from '../actions/auth_types' export default function(state = {}, action) { switch(action.type) { case AUTH_USER: return { ...state, authenticated: true } case UNAUTH_USER: return { ...state, authenticated: false } } return state }
从文档中:
由于对象传播语法仍然是ECMAScript的第2阶段建议,因此您需要使用Babel这样的编译器在生产中使用它。您可以使用现有的es2015预设,安装babel- plugin-transform-object-rest- spread并将其分别添加到中的插件数组中.babelrc。
.babelrc
{ "presets": ["es2015"], "plugins": ["transform-object-rest-spread"] }
请注意,这仍然是实验性的语言功能建议,因此将来可能会更改。