Skip to content

use_context_provider example #172

Answered by t1m0t
t1m0t asked this question in Q&A
Discussion options

You must be logged in to vote

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();

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by t1m0t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant