user8672583
user8672583

Reputation:

I have an unexpected token error. Where is it coming from?

I'm being told there is an unexpected token error in my mapStateToProps function, but I'm failing to find it. Can you take a look and tell me what the problem is?

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)

The error from my computer reads...

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.

Thanks in advance.

Upvotes: 0

Views: 39

Answers (1)

Tyler Sebastian
Tyler Sebastian

Reputation: 9458

receipt: { receiptProducts: [] } instead of receipt: { receiptProducts = [] }

You would typically use { x = [] } when setting a default value for unpacking

const { x = [] } = someVariable

in this case, though, you're just building a javascript object, so you only use :s

Upvotes: 2

Related Questions