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

问题描述 投票:0回答:1

我被告知我的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.

提前致谢。

javascript reactjs react-redux
1个回答
2
投票

receipt: { receiptProducts: [] }而不是receipt: { receiptProducts = [] }

在设置解包的默认值时,通常会使用{ x = [] }

const { x = [] } = someVariable

但是,在这种情况下,您只是构建一个javascript对象,因此您只使用:s

© www.soinside.com 2019 - 2024. All rights reserved.