Im making a modal in my React project that requires a class to be added to the body when the modal is open and removed when it is closed.
I could do this the old jQuery
Actually you don't need 2 functions for opening and closing, you could use document.body.classList.toggle
document.body.classList.toggle
const [isOpen, setIsOpen] = useState(false) useEffect(() => { document.body.classList.toggle('modal-open', isMobileOpen); },[isOpen]) setIsOpen(!isOpen)}>Toggle Modal