I'm working on a darkmode toggle on my fresh site and I want to export a small script tag as part of the rendered html (to avoid the "flash" of light mode that can happen before the .js files are loaded)
This is how I am doing it in my island:
return (
<>
<Head>
<script>
let dark = localStorage.getItem('darkmode');
document.querySelector(':root')?.classList.toggle('dark', dark === 'true');
</script>
</Head>
</>
I'm wondering if there is a more elegant way to do this?