Home>

I have a code like this in react. =>How is the ({}) part handled?

const Props = d =>({
  onClick (id) {
    d (todo (id));
  }
});
  • Answer # 1

    Hello

    const Propsis a function. What kind of function is

    Takes one argumentd. Thatdis also expected to be a function.

    Returns an

    object. The object has a property calledonClick, and the value of theonClickproperty is also a function.

    onClickis a function that takes one argument,id, and the previously given functiontodoandPropsd (todo (id))using the functiondgiven as an argument to/code>.

    The following is a sample to confirm the above.

    Codepen for operation check: https://codepen.io/jun68ykt/pen/QWWRyvP?editors=0012