Peepee Verisoft
Peepee Verisoft

Reputation: 3

passing a parameter and other props to a component in react

{cartItems.map((item, pos) =>{
    return (
        <div className="item-container" key ={pos}>
            <Item {...item } setIsLoading={setIsLoading}  />
        </div>
    )
})}

when I try to call setIsLoading in Item, it gives me an error saying that

"Uncaught TypeError: setIsLoading is not a function"

I am also not very sure if the header was written correctly:

const Item = (product, setIsLoading) => {
    //....
    setIsLoading(true);
}

it was working fine before I added setIsLoading. I am a bit confused about what the problem is.

Upvotes: 0

Views: 57

Answers (1)

Saul Moreyra
Saul Moreyra

Reputation: 161

Props in a component is only an object You can see the documentation here

But for now you can destructure the props

const Item = ({setIsLoading, ...product}) => {
    //....
    setIsLoading(true);
}

Upvotes: 1

Related Questions