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

193
Visualizações
React-bootstrap Modal is not popping up onClick of function

I am working in a jhipster application. when I create my own modal and set the state to true, my custom modal shows on initial render of my application, but when I set it to false and try to call the modal through my function,it does not appear.

Then when I call the handleShow(), the alert saying "hello" appears on the browser, but it does not call the setShow().

I have also tried to use the inbuilt modal of jhipster, but it seems I have to pass a specific URL containing an id before it will appear

imports

 import { Modal } from 'react-bootstrap';

state

    const [showModal, setShow] = useState(false);
     

Modal function

    const handleClose = () => setShow(false);
    const handleShow = () => {
    alert('hello');
    setShow(true);
  };

Delete function

   const handleDelete = row => {
   dispatch(deleteEntity(row));
  };

The bootstrap action column and Modal content

    {
  dataField: 'databasePKey',
  text: 'Actions',
  headerStyle: { backgroundColor: 'red', color: 'white' },
  formatter: (cellContent, row) => {
    return (
      <>
        <div className="btn-group flex-btn-group-container">
          <Button onClick={() => handleShow()} color="danger" size="sm" 
      data-cy="entityDeleteButton">
            <FontAwesomeIcon icon="trash" /> <span className="d-none d- 
      md-inline"></span>
          </Button>
          {showModal === true ? <Modal /> : null}
        </div>
        <Modal show={showModal} onHide={handleClose}>
          <Modal.Header closeButton>
            <Modal.Title>Confirm delete operation</Modal.Title>
          </Modal.Header>
          <Modal.Body>Are you sure you want to delete this Terminal? 
         </Modal.Body>
          <Modal.Footer>
            <Button variant="secondary" onClick={handleClose}>
              Cancel
            </Button>
            <Button variant="primary" onClick={() => 
          handleDelete(row.id)}>
              Confirm
            </Button>
          </Modal.Footer>
        </Modal>
       </>
      );
      },
      },
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Here is the mistake: handleShow is function. You should check for state variable when calling ModalContent component

Fixed code:

    <div className="btn-group flex-btn-group-container">
        <Button onClick={() => handleShow()} color="danger" size="sm" datacy="entityDeleteButton">
          <FontAwesomeIcon icon="trash" /> <span className="d-none d-md-inline"></span>
        </Button>
        {showModal === true ? <ModalContent /> : null}
    </div>
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