How to access Bootstrap methods when using React and adding the bootstrap CDNS to the index.html page? I added bootstrap v5.0 to my react app

Viewed 34

I added bootstrap v5.0 to my react app by inserting the bootstrap Scripts directly to the index.html, so now i can't access the bootstrap methods.


   HandleLogIn = () => {
       const loginForm = document.querySelector('#login-form');
       loginForm.addEventListener('submit', (e) => {
         e.preventDefault();
         const email = loginForm['inputEmail-login'].value;
         const password = loginForm['inputPassword-login'].value;
         this.auth
           .signInWithEmailAndPassword(email, password)
           .then((res) => {
             console.log('You are Logged In');
           })
           .catch((err) => {
             console.log(err.code);
           });
         let modal = document.querySelector('#modal-logIn');
         let newModal = bootstrap.Modal.getInstance(modal);
         newModal.hide();`enter code here`
         loginForm.reset();
       });
     };

react will say bootstrap is not defined The hide() method will not work as well.

1 Answers

I don't think that will work the way you hope. For one thing, bootstrap loaded from the index.html won't have access to react's virtual Dom.

Instead, try loading bootstrap into react using something like React Bootstrap. https://react-bootstrap.github.io/

Related