在Redux中传播属性

编程入门 行业动态 更新时间:2024-10-28 10:36:31
本文介绍了在Redux中传播属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试在我的Reducer中使用spread属性,但它返回时语法错误无效。我的构建支持使用扩展运算符,因为我只在我的Redurs中得到错误。

I am trying to use the spread properties in my reducers, but it is coming back with an invalid syntax error. My build supports the use of the spread operator as I only get the error in my reducers.

auth_types.js

auth_types.js

export const AUTH_USER = 'AUTH_USER' export const UNAUTH_USER = 'UNAUTH_USER'

auth_actions.js

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

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 中的插件数组。

Since the object spread syntax is still a Stage 2 proposal for ECMAScript you’ll need to use a transpiler such as Babel to use it in production. You can use your existing es2015 preset, install babel-plugin-transform-object-rest-spread and add it individually to the plugins array in your .babelrc.

{ "presets": ["es2015"], "plugins": ["transform-object-rest-spread"] }

请注意,这仍然是一个实验性语言功能提案,所以它可能会在未来。

Note that this is still an experimental language feature proposal so it may change in the future.

更多推荐

在Redux中传播属性

本文发布于:2023-10-28 00:32:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1534979.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   Redux

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!