Add class to body with React

const [isOpen, setIsOpen] = useState(false)
useEffect(() => {
  document.body.classList.toggle('class-open', isOpen);
},[isOpen])
    
<button onCLick={()=> setIsOpen(!isOpen)}>Toggle Class</button>

Leave a Reply

Your email address will not be published. Required fields are marked *