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

287
Views
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 answers
Answer question

0

The function can just return null:

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

0

Use this:

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

0

Maybe try returning void instead?

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