-
I have a peculiar issue where I need to #[derive(Clone, Debug)]
enum Mode {
Light,
Dark,
}
impl Display for Mode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Light => write!(f, "light"),
Self::Dark => write!(f, "dark"),
}
}
}
pub fn shell(options: LeptosOptions) -> impl IntoView {
let mode = RwSignal::new(Mode::Dark);
provide_context(mode);
view! {
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<HotReload options=options.clone() />
<HydrationScripts options />
<MetaTags />
</head>
<body class=move || {
format!("p-8 bg-background text-foreground {}", mode.read())
}>
<App />
</body>
</html>
}
} Later in a route, I setup this way: #[component]
fn Home() -> impl IntoView {
let mode = expect_context::<RwSignal<Mode>>();
let on_switch_mode = move |_| {
let result = mode.get_untracked();
leptos::logging::log!("mode: {:?}", result);
match result {
Mode::Light => mode.set(Mode::Dark),
Mode::Dark => mode.set(Mode::Light),
}
};
view! {
<div class="grid gap-4 place-items-start">
<div>
<Button
variant=ButtonVariant::SECONDARY
size=ButtonSize::ICON
class="size-8"
on:click=on_switch_mode
>
<Sun />
</Button>
</div>
</div>
}
} But I get an error on page load: panicked at /home/ubuntu/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/reactive_graph-0.2.0/src/owner/context.rs:305:9:
Location { file: "src/app.rs", line: 132, col: 16 } expected context of type "reactive_graph::signal::rw::RwSignal<sizzle_ui::app::Mode>" to be present Is the shell not constructed client side and only the body hydrated with Any pointer will be greatly appreciated. Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Okay I just realized there is a |
Beta Was this translation helpful? Give feedback.
Okay I just realized there is a
<Body />
component that I can use: https://book.leptos.dev/metadata.html?highlight=Body#body-and-html