-
Can I get an example on how to use |
Beta Was this translation helpful? Give feedback.
Answered by
t1m0t
Jan 28, 2022
Replies: 1 comment
-
answered by @jkelleyrtp on discord: for the simplest use_cases of providing immutable context, but for use_context_provider, it can really only be used with |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
t1m0t
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
answered by @jkelleyrtp on discord:
for the simplest use_cases of providing immutable context,
let state = cx.use_hook(|_| cx.provide_context(state));
works fine
but for use_context_provider, it can really only be used with
use_context
To provide context:
use_context_provider(&cx, || MyContext::new())
To consume context:
let state = use_context::<MyContext>(&cx).unwrap();