-
|
This simple example panics on #[derive(Clone,Copy)]
pub struct State {
pub counter: RwSignal<i32>
}
#[component]
fn App() -> impl IntoView {
view! {
<Provider value=State { counter: RwSignal::new(0) }>
<button on:click=move |_| {
let state = use_context::<State>().unwrap();
state.counter.update(|i| *i += 1);
}>"Click Me"</button>
{
let state = use_context::<State>().unwrap();
state.counter
}
</Provider>
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
gbj
Nov 6, 2025
Replies: 1 comment
-
|
Context is available in the body of a component, but is not available in things that run outside the component tree, like event listeners. You can |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
mahdi739
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Context is available in the body of a component, but is not available in things that run outside the component tree, like event listeners. You can
use_contextin the body of the component, and then move it into the event listener, instead.