add classnames to body 1

add classnames to body

openModal = (event) => {
  document.body.classList.add('modal-open');
  this.setState({ showModal: true });
}
hideModal = (event) => {
  document.body.classList.remove('modal-open');
  this.setState({ showModal: false });
}

Here is what the above code is Doing:
1. We’re creating a state variable called showModal and setting it to false.
2. We’re creating a function called openModal that sets showModal to true and adds a class to the body tag called modal-open.
3. We’re creating a function called hideModal that sets showModal to false and removes the class from the body tag.

Now that we have our functions, let’s add the modal to our render function.

Similar Posts