Home > Enterprise >  How to pass an object inside of prop as function argument in React? // I want to pass props.item as
How to pass an object inside of prop as function argument in React? // I want to pass props.item as

Time:05-19

I am not able to pass props.item as argument to the function. What is the way to pass it ?

CodePudding user response:

You don't have to pass it as an argument to the function. You can use props as a global object.

const handleIncrement = () => {
   console.log(props.item);
  //you can use your props.item here
}

CodePudding user response:

Check your code, it should be like :

const handleIncrement = (item) => {...}

And when you call the fucntion you pass the item from prop as params. like this:

handleIncrement(prop[item]})

if item is a key in the prop object, so :

handleIncrement(prop["item"]})

OR

handleIncrement(prop.item})
  • Related