Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Uncaught TypeError: confirm is not a function

i have my simple code snippet and i’m trying to run but I’m getting the error " Uncaught TypeError: confirm is not a function"

import { Modal } from "react-bootstrap"

const { confirm } = Modal;
function delete(param){
 confirm({
  title: "Do you Want to delete this message?",
  icon: <AiOutlineExclamationCircle />,
  content: message, 
 });
}

return (<Button onClick={() => delete()}>Delete</Button>)

I’m not finding a solution how to fix this. Someone help.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

There is no confirm option on Modal API. I guess what you want is to show the Modal as a confirmation modal. To do so you should do something like:

import { Modal } from "react-bootstrap"

const YourComponent = () => {
  const [showModal, setShowModal] = useState(false)

  const handleClose = () => {
   // Your logic here
   setShowModal(false)
  }

  return (
    <>
      <Modal show={showModal} onHide={handleClose}>
        <Modal.Header closeButton>
          <Modal.Title>Do you Want to delete this message?</Modal.Title>
        </Modal.Header>
        <Modal.Body>Some body message</Modal.Body>
        <Modal.Footer>
          <Button variant="secondary" onClick={handleClose}>
            no
          </Button>
          <Button variant="primary" onClick={handleClose}>
            yes
          </Button>
        </Modal.Footer>
      </Modal>
      
      <Button onClick={() => setShowModal(true)}>Delete</Button>
    </>
  )
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading