我被告知我的 mapStateToProps 函数中存在意外 token 错误,但我无法找到它。你能看一下并告诉我问题是什么吗?
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.
提前致谢。
最佳答案
收据:{receiptProducts:[]}
而不是收据:{receiptProducts = []}
设置解包默认值时,您通常会使用{ x = [] }
const { x = [] } = someVariable
但在本例中,您只是构建一个 javascript 对象,因此您只使用 :
s
关于javascript - 我遇到意外的 token 错误。它从哪里来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49138169/