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

102
Views
React can't fire onClick

All the events on the Article: onMouseMove, onMouseDown etc. are correctly executed. But onClick don't. I can see the button but clicking in it nothing happens.

Button showed

const onDelete = () => {
  console.log('delete')
};

return (
  <>
    {show &&
      <Ul style={{top: pos.y, left: pos.x}}>
        <Li>
          <Button onClick={onDelete}>
            <Trash /> Delete
          </Button>
        </Li>
      </Ul>
    }
    <Article ref={ref} onContextMenu={onRightClick}
      onMouseMove={onMouseMove} onMouseDown={onMouseDown} onMouseUp={onMouseUp} onMouseLeave={onMouseLeave}
    >
      {children}
    </Article>
  </>
);

If I move the code in brackets to inside Article, onClick is fired but the style of Ul doesn't work properly. I have other components that execute events correctly being inside brackets. But for some reason this component only executes the events in the Article.

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

0

I found the answer. I had another function that closes that button when I click outside the button (using ref). But when I clicked in button that function was fired because I was using same ref. I just had to use another ref and worked!!!

useClickOutside(ref2, () => setShow(false));

const onDelete = () => {
  console.log("delete");
};

return (
  <>
    {show &&
      <Ul style={{top: pos.y, left: pos.x}}>
        <Li>
          <Button ref={ref2} onClick={onDelete}>
            <Trash /> Delete
          </Button>
        </Li>
      </Ul>
    }
    <Article ref={ref} onContextMenu={onRightClick}
      onMouseMove={onMouseMove} onMouseDown={onMouseDown} onMouseUp={onMouseUp} onMouseLeave={onMouseLeave}
    >
      {children}
    </Article>
  </>
);
about 4 years ago · Juan Pablo Isaza Report

0

Try this:

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