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

294
Vistas
How to create a function that doesn't do anything in React

There is a component that must be build which must receive a function for onClick. The problem is that the function is not defined yet so it must receive some 'empty' function in order to pass the tests.

This is the code:

  <Button
    title='MyTitle'
    className='my-class-name'
    onClick={
      () =>
        /* eslint-disable no-console */
        console.log('test')
      /* eslint-enable no-console */
    }
  />

So I added a console.log() but eslint doesn't like it so the comments before and after it were added.

Is there a way to put a function that doesn't do anything just to pass the linting?

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

The function can just return null:

   <Button
        title='MyTitle'
        className='my-class-name'
        onClick={() => null}
    />
about 4 years ago · Juan Pablo Isaza Denunciar

0

Use this:

<Button
    title='MyTitle'
    className='my-class-name'
    onClick={
      () => undefined
    }
  />
about 4 years ago · Juan Pablo Isaza Denunciar

0

Maybe try returning void instead?

onClick={() => void 0}
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