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

155
Views
facing quite strange issue in popup closing in react. method is getting called but popup is not closing

I have created one component. in which I have a button in which once you click popup will be displayed. data for that popup is put in another component. below is the popup.

enter image description here

the problem is once I am clicking on the cross(x) button at corner my popuup is not getting closed.

below is the code to launch popup.

const [statusUpdateFlag, setStatusUpdateFlag] = useState(false);
     <td>
                    <button type="button" onClick={(event) => handleStatusUpdateClick(event)}>
                     click
                    {statusUpdateFlag && (
                      <StatusUpdate
                                certificate={props.certificate}
                                handleStatusUpdateClick={handleStatusUpdateClick}
                                closePopUp={closePopUp}
                            />
                    )}       
                    </button>
          </td>

once user click on the button , statusUpdateFlag will be true popup will be launched.

 const handleStatusUpdateClick = async (event: SyntheticEvent) => {
        event.preventDefault();
        setStatusUpdateFlag(true);
 } 

now on the close button I have just made setStatusUpdateFlag(false); . even this method is getting called. still popup is not closing.

const closePopUp = (event: any) => {
        alert("closepopup called");
        event.preventDefault();
        setStatusUpdateFlag(false);
    };

once I click X method is getting called but popup is not closing. enter image description here

below is code for X button,

<button
  className={styles.closeicon}
  onClick={(event) => props.closePopUp(event)}
>
  x
</button>

what mistake I am doing?

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

0

You have written the Popup component as children of your button, so when you click on popup close, a trigger for parent button click is also triggered so popup visible state is again set true.

const [statusUpdateFlag, setStatusUpdateFlag] = useState(false);
<td>
    <button type="button" onClick={(event) => handleStatusUpdateClick(event)}>
        click
        {/* Issue is here */}
        {statusUpdateFlag && (
            <StatusUpdate
                certificate={props.certificate}
                handleStatusUpdateClick={handleStatusUpdateClick}
                closePopUp={closePopUp}
            />
        )}
    </button>
</td>;

You should bring out the StatusUpdate component outside button and in my opinion for UI, outside the whole table component if possible. That should fix the issue.

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!