Skip to content

Islands that client-side-render only instead of hydrating? #3474

Answered by gbj
lnay asked this question in Q&A
Discussion options

You must be logged in to vote

Sure! Here's an example of a client-only island. (Or a client-only anything to be honest. The trick is that an Effect only runs on the client, and that it runs after hydration, so you can mutate a signal in an Effect and use it to say "only show this on the client.")

#[island]
pub fn ClientOnlyIsland() -> impl IntoView {
    let render = RwSignal::new(false);
    Effect::new(move |_| render.set(true));
    move || {
        render.get().then(|| {
            view! {
                <h2>"Client-Only Island"</h2>
            }
        })
    }
}

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by lnay
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants