Nora
Nora

Reputation: 23

How to add two Actions to a button In react.js

I have a problem in combine 2 action in the same button

<Button
disabled={!isFormValid}`
onClicked={this.submitHandler}
/>

I want to add this function with the previous one

() => this.popUpHandler('update');

This my code

The first action to submit form and next to close popup after that. Do you have any idea about it?

Upvotes: 0

Views: 3407

Answers (2)

0stone0
0stone0

Reputation: 44093

Use Anonymous_functions.

<Button
    disabled={!isFormValid}
    onClicked={ () => {
        this.popupHandler("Update");
        console.log('Button clicked');
    }}
/>

Or create a separate handler;

Class Something extends React.Component {
  onButtonClick() {
      // Do anything
      this.popupHandler("Update");
      console.log('Button clicked');
  }

  render() {
    return (
        <Button
            disabled={!isFormValid}
            onClicked={this.onButtonClick()}
        />
    );
  }
}

Upvotes: 1

Sundar Ban
Sundar Ban

Reputation: 619

You can simply use

    submitHandler(){
    //after some condition  you can call here another function

    this.popUpHandler('update')

    }
    popUpHandler(var){
    //your logic
    }
<Button
    disabled={!isFormValid}
    onClicked={this.submitHandler}
/>

Upvotes: 0

Related Questions