Function freya::prelude::use_context
pub fn use_context<T>() -> Twhere
T: 'static + Clone,
Expand description
Consume some context in the tree, providing a sharable handle to the value
Does not regenerate the value if the value is changed at the parent.
fn Parent() -> Element {
use_context_provider(|| Theme::Dark);
rsx! { Child {} }
}
#[component]
fn Child() -> Element {
//gets context provided by parent element with use_context_provider
let user_theme = use_context::<Theme>();
rsx! { "user using dark mode: {user_theme == Theme::Dark}" }
}