I'm using Bootstrap for my React project, I'm not using react-strap or react-bootstrap only pure Bootstrap. I have a modal for entry form data, to handle show or hide the modal I following from bootstrap documentation. Below how I show the modal and its work:
import { Modal } from "bootstrap/dist/js/bootstrap.bundle";
const showModal = () => {
const modal = new Modal(document.querySelector("#exampleModal"));
modal.show();
}
And now I want to hide the modal after submitted form data, so this is how I hide the modal:
const hideModal = () => {
const modal = new Modal(document.querySelector("#exampleModal"));
modal.hide();
}
const submitNewNote = (e) => {
e.preventDefault();
const notes = {
titleNote: titleNote,
tasks: [...temporaryNote]
}
fetch("http://localhost:8000/notes", {
method: "POST",
headers: {"Content-Type": "application/json"},
body: JSON.stringify(notes)
})
.then(response => response.json())
.then(data => {
console.log("New data added", data);
hideModal();
})
.catch(err => console.log(err))
}
But it's not working like how I show the modal. Do you know what is wrong or you have another solution to show/hide the modal? Thanks!