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

140
Views
when using onClick event with callback is not listen on React functional component in react

I have one flyout that listens to the onClick event to open to a new tab then close it. When I bypass the onClick function onClickOption as props, it is working but when I set it up as onClick inline callback function, the flyout is not close after clicking any <li>. anyone may know why? codebox

import './styles.css';
import React, { FC, useRef, useState } from 'react';
import Flyout from './Flyout';
interface OptionPanelProps extends React.HTMLAttributes<HTMLElement> {}

const noOp = (): void => void 0;

export const OptionPanel: FC<OptionPanelProps> = () => {
  const openNewTab = (): void => {
    window?.open(`google.com`, '_blank');
  };
  return (
    <div>
      <ul>
        <li onClick={() => openNewTab()}>1</li>
        <li onClick={() => openNewTab()}>2</li>
        <li onClick={() => openNewTab()}>3</li>
      </ul>
    </div>
  );
};

export const OptionFlyout: FC = () => {
  const [isFlyoutOpen, toggleFlyout] = useState(false);
  const anchorRef = useRef < HTMLButtonElement > null;

  const closeFlyout = (): void => {
    toggleFlyout(false);
  };

  return (
    <div className="recentSearch" data-tn="recentSearch-flyout">
      <button ref={anchorRef}>Option Menu</button>
      <Flyout
        anchor={anchorRef.current}
        isOpen={isFlyoutOpen}
        onDismiss={closeFlyout}>
        {isFlyoutOpen && <OptionPanel onClick={() => closeFlyout()} />}
      </Flyout>
    </div>
  );
};

export default function App() {
  return (
    <div className="App">
      <OptionFlyout />
    </div>
  );
}
about 4 years ago · Juan Pablo Isaza
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!