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

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

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 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