Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

299
Visualizações
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 Respostas
Responde à pergunta

0

The function can just return null:

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

0

Use this:

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

0

Maybe try returning void instead?

onClick={() => void 0}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda