Context

Context passes serializable values down the component tree without prop drilling.

Define a context

#[derive(Clone, Serialize, Deserialize)]
struct Locale {
    lang: String,
}

static LOCALE: ContextId<Locale> = ContextId::new();

Provide and consume

#[component]
fn App() -> View {
    provide_context(&LOCALE, Locale { lang: "en".into() });
    view! { <Page /> }
}

#[component]
fn Page() -> View {
    let locale = use_context(&LOCALE);
    view! {
        <p>"Language: " {locale.lang.clone()}</p>
    }
}

Resumability

Context values are serialized in the resumability payload. Descendants can read them on the client after resume without re-fetching from the server.

Theme helper

For theming, see Theme cookbook which wraps context with provide_theme / use_theme.