If you use a framework component with a client directive of client:only
, you may see a flash of no content until the component renders.
In this case, it may be useful to show a loading state like a spinner or skeleton until the component loads - especially if it will take longer than a second.
One way to do this is to use a separate loading element alongside your framework component, and hide or remove that element once the component mounts.
React example
Vue example
Svelte example
Alternative
If you’re using another directive like client:load
or client:visible
, your component’s initial view (before it hydrates) may render right away.
In this case, you probably don’t need to do anything. But if you still need to show a loading state, then you can handle this within the component itself. For example, you could add a loading spinner within the component, and then conditionally render the final view once it’s ready (with state).