Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
why the onclick with parameters will execute imediate in react

I have a button with onclick in react like this:

<Button onClick={this.editApp} type='link'>
                            Edit
                        </Button>

when I added a parameter with the function, it will be execute imediate:

<Button onClick={this.editApp(record)} type='link'>
                            Edit
                        </Button>

why the onclick will execute imediate with a parameter? this is the function define:

editApp = (row) => {
        this.setState({
            isEditModalVisible: true,
            editRowData: row
        })
    }

because the function will execute imediate, make it going into a dead loop. why would this happen and what should I do to fix it? does it mean it will be better way to write the onclick with an arrow function no matter it does a parameter or not?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

It is executing immediately because you invoked it there. onClick expects a function and not its return value. If you want to pass argument to a function, then you should wrap it in another function.

<Button onClick={() => this.editApp(record)} type='link'>
  Edit
</Button>
about 4 years ago · Juan Pablo Isaza Report

0

You need to create an anonymous function if you want to have a parameter passed in by default:

<Button onClick={() => this.editApp(record)} type='link'>
                            Edit
                        </Button>
about 4 years ago · Juan Pablo Isaza Report

0

The function is running immediately when the button is rendered because it is being called you need to wrap it in the anonymous function to work.

try this

<Button onClick={() => this.editApp(record)} type='link'>
  Edit
</Button>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!