How can i run some dom manip before rendering?
Hello I want to run some javascript that will change classes of the body tag before display. How can I do this?
6 Replies
basically I have a localStorage value that determines if the site will be dark or light themed, but for some reason this code runs after it has already rendered leading to a flickering effect.
Did you configure the app to be client only?
Because by default, solid start will render the page on the server and there is no local storage why you‘d better be using a cookie.
Or have a look at kobalte.dev‘s implementation:
https://github.com/kobaltedev/kobalte/tree/main/packages/core/src/color-mode
GitHub
kobalte/packages/core/src/color-mode at main · kobaltedev/kobalte
A UI toolkit for building accessible web apps and design systems with SolidJS. - kobaltedev/kobalte
can you help me make it client only?
idk how to do that
For just one component there’s the clientOnly helper:
https://docs.solidjs.com/solid-start/reference/client/client-only
For the entire app:
app.config.ts
Add:
{
ssr: false
}
holy cow it works
thank youuu
You’re welcome ☺️