reactjssweetalert

How to render a react component in sweetalert2 innerhtml?


This is my code which i want render CarReport component in a sweetalert modal. <CarReport /> is just a simple form.

Swal.fire({
        title: "..."
        html: <CarReport />, //How to write this line?
        confirmButtonText: "Check",
        preConfirm: () => {
            //api request
        },
      });

Currently this code opens the modal but shows [object object] in body of the modal.


Solution

  • SweetAlert2 does not support react components. For that it requires using

    sweetalert2-react-content