Function turning empty object when sent as props (React)

Asked

Viewed 33 times

0

I’m having trouble sending a function from one component to another.

The function:

const plus = () => {
  setQuantity(quantity + 1);
}

Send as a prop in the "Cart"

<Cart chosen={productDataObj} allchosen={chosenProducts} quantity={quantity} plus={plus}/>

I check which type of variable "plus" is returning within that component and it returns as an object Output do console

Initial excerpt from Cart.js

import React from 'react';
import ProductCard from './ProductCard';

export default function Cart(chosen, plus){
 
const allChosen = chosen.allchosen;

 console.log(typeof(plus)) 

In another component, at the same level of Cart, where I pass another function, it arrives correctly.

Thanks in advance!

1 answer

-1

is missing the structuring of props just like I put down:

export default function Cart({chosen, plus}){

         seu componente ou console.log(typeof(plus))
   


}
  • I tried so but the return is equal :(

Browser other questions tagged

You are not signed in. Login or sign up in order to post.