I have component with button and 2 functions.Button component used in various components. And for some need one function for onclick event, for other - second. How can I change functions for onclick event? I'm using this answer, but always getting undefined in my components.
export default class MyButtonComponent extends Component {
constructor(props) {
super(props);
propTypes: {
onClick: PropTypes.func
};
this.state = { loading: false, api_url: "http://localhost:8000" };
}
static get DefaultProps() {
return {
onClick: this.firstFunction(event)
}
}
firstFunction(){
/*some code*/
}
secondFunction(){
/*some code*/
}
render() {
return (
<LaddaButton
loading={this.state.loading}
onClick={this.props.onClick}
className='submit'
data-color="#eee"
data-style={SLIDE_UP}
data-spinner-size={30}
data-spinner-color="#ddd"
data-spinner-lines={12}
data-url={this.props.url}
>
Отправить
</LaddaButton>
);
}
And in another component:
<FormGroup>
<Col mdOffset={5} md={7}>
<MyButtonComponent onClick={this.secondFunction} data-url="someurl.com"></MyButtonComponent>
</Col>
</FormGroup>
Also tried add
onClick={e => this.secondFunction(e)}
to button componentm but always getting error
_this2.secondFunction is not a function