score:1

Accepted answer
const [active, setActive] = useState(false)
const modeRef = useRef();

const handleToggle = () => {
     modeRef.current.classList.toggle("dark")
}

return (
    <button ref={modeRef} className="mode-switch" title="Switch Theme" onClick={handleToggle}>
          <svg className="moon" fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" width="24" height="24" viewBox="0 0 24 24">
            <defs></defs>
            <path d="M21 12.79A9 9 0 1111.21 3 7 7 0 0021 12.79z"></path>
          </svg>
    </button>
)

Related Query

More Query from same tag