In react how do I pass the identifier of the button that was clicked on to the parent component if my click handler returns an async function?
In the parent:
jumpToItem = async () => {
const { activeItem } = this.props;
...
}
I'm passing to the handler to the child like this:
<ItemSelector activeItem={activeItemIndex} itemsCount={itemsNumber} onClick={this.jumpToItem} />
In the child component:
return (
<Item key={index} {...itemProps} onClick={this.props.onClick} />
);
Can I pass the index of the clicked item all the way up to JumpToItem ? Do I need to do something like this?
jumpToItem = async (index) => {
const { activeItem } = this.props
// ...do something with index...
}
or do I have to pass the parameter like this:
jumpToItem(index) = async () => {
const { activeItem } = this.props
// ...do something with index...
}