Parsing Error: Unexpected token

Hi friends,

I’m getting a little trouble putting that to work.
This method intend to put check if there’s a product in the cart, if true, sum the same product.

	onAddProductToCart = (productId) => {
		const productInCart = this.state.productsInCart.find(
			(product) => productId === product.id
		);

		if (productInCart) {
			const newProductsInCart = this.state.productsInCart.map(product => {
				if(productId === product.id) {
					return {
						...product,
						quantity = product.quantity + 1
					}
				}
				return product
			})
			
			this.setState({productsInCart: newProductsInCart})
		}
	};

I’m getting this error point to my assignment “=” bellow
Parsing error unexpected token:

quantity = product.quantity + 1

This method is inside the App class component , with has some mocked data.

class App extends Component {
	state = {
		minFilter: "100",
		maxFilter: "2000",
		nameFilter: "Produto",
		productsInCart: [
			{
				id: 3,
				name: "Produto 3",
				price: 300.77,
				photo: "https://picsum.photos/200/200?a=3",
				quantity: 1,
			},
			{
				id: 4,
				name: "Produto 4",
				price: 400,
				photo: "https://picsum.photos/200/200?a=4",
				quantity: 2,
			},
		],
	};

Hello!

I think you cannot write both:

...product,
quantity = product.quantity + 1

Can you do it this way?

...product,
quantity: product.quantity + 1
1 Like

That’s it, solved.

Thanks