Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix use_context example in docs #1770

Merged
merged 1 commit into from
Feb 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/concepts/function-components/pre-defined-hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ pub fn app() -> Html {
});

html! {
<ContextProvider<Theme> context=ctx>
// `ctx` is type `Rc<Theme>` while we need `Theme` so we deref it
<ContextProvider<Theme> context=(*ctx).clone()>
// Every child here and their children will have access to this context.
<Toolbar />
</ContextProvider<Theme>>
Expand All @@ -315,7 +316,7 @@ pub fn toolbar() -> Html {
/// As this component is a child of `ThemeContextProvider` in the component tree, it also has access to the context.
#[function_component(ThemedButton)]
pub fn themed_button() -> Html {
let theme = use_context::<Rc<Theme>>().expect("no ctx found");
let theme = use_context::<Theme>().expect("no ctx found");

html! {
<button style=format!("background: {}; color: {};", theme.background, theme.foreground)>
Expand Down