Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

124
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda