how are things being passed to onClick function

Viewed 56

I was reviewing a code there user have done something like this

<temp onClick={this.onSelected} />

where onSelected looks like this

onSelected = (id: string) => {
    [...]
}

How is id: string passed here?

Also, out of curiosity (not primary function). what will be the difference between

onClick={() => this.onSelected()}

and

onClick={this.onSelected}
1 Answers

The component <temp> probably has some code similar to

props.onClick("some-id");

Which in turn will call the onSelected function with id: string = "some-id"

Related