I was curious how one may be able to access data within a map function so that it can be used within the event parameter when passing down a function within an onClick function in React.
Here is my handleClick function. I would like to gain access to the "d" named property from the map function using the event in handleClick If there's another way to gain access to the variable "d" so that I could use it in handleClick that would be really great. I couldn't find a specific solution for this type of scenario so I was wondering if I could get some help. Thanks!
// Gain access to the parameter data from the map function
public handleClick(event: React.MouseEvent<HTMLAnchorElement>) {
console.log(event);
}
public render() {
return (
<div className="">
{this.props.data.slice(0, MAX_RESULTS_LENGTH).map((d: any) => (
<a tabIndex={0} onClick={this.handleClick} key={d.id}>
{d.address}
</a>
))}
</div>
);
}
}