我有一个意外的令牌错误。它来自哪里?

时间:2018-03-06 19:01:29

标签: javascript reactjs react-redux

我被告知我的mapStateToProps函数中存在意外的令牌错误,但我没有找到它。你能看看并告诉我问题是什么吗?

import React from 'react'
import { connect } from 'react-redux'
import { Redirect } from 'react-router-dom'

const mapStateToProps = state =>({
  config: state.config,
  receipt: { receiptProducts = [] },
  expeditedShipping: state.expeditedShipping.expeditedProduct
})

@connect(mapStateToProps)

计算机出错...

ERROR in ./src/client/app/cbd-
mobile/components/receipt/ReceiptComponent.js
Module build failed: SyntaxError: Unexpected token, expected , (8:26)

   6 |   config: state.config,
   7 |   receipt: { receiptProducts = [] },
>  8 |   expeditedShipping: state.expeditedShipping.expeditedProduct
     |                           ^
   9 | })
  10 | 
  11 | @connect(mapStateToProps)

 @ ./src/client/app/index.jsx 31:24-83
 @ multi (webpack)-dev-server/client?http://localhost:8080 
./src/client/app/index.jsx
webpack: Failed to compile.

提前致谢。

1 个答案:

答案 0 :(得分:2)

receipt: { receiptProducts: [] }代替receipt: { receiptProducts = [] }

在设置解包的默认值

时,通常会使用{ x = [] }
const { x = [] } = someVariable
但是,在这种情况下,你只是在构建一个javascript对象,所以你只使用: s