Following is my code snippet
Child Class function (handleClick)
import React, { Component } from 'react';
import {render} from 'react-dom';
export class Badge extends Component {
handleClick() {
alert("this and that")
}
render() {
return (
<button whenClicked={this.handleClick} className={"btn " + this.props.className} type="button">
{this.props.title} <span className={this.props.subTitleClassName}>{this.props.subTitle}</span>
</button>
);
}
}
Parent Class
export class Dropdown extends Component {
render() {
return (
<div className="dropdown">
<Badge onClicked={this.props.whenClicked} className="btn btn-default" title={this.props.title} subTitleClassName="caret" />
</div>
);
}
}
In above code whenever I try to call handleClick function in child class it is not working.
onClick. You can't name it anything you want. Also, what are you trying to do with this ? The event handler should be define in Dropdown classBadgeis the child component, and theDropdownis the parent component. So you want theDropdownto handle a click on thebuttoninBadge?