diff --git a/docs/book/src/view/08_parent_child.md b/docs/book/src/view/08_parent_child.md index 4d9b526c96..ffd0126cf9 100644 --- a/docs/book/src/view/08_parent_child.md +++ b/docs/book/src/view/08_parent_child.md @@ -72,9 +72,7 @@ pub fn App() -> impl IntoView { #[component] -pub fn ButtonB(on_click: F) -> impl IntoView -where - F: Fn(MouseEvent) + 'static, +pub fn ButtonB(#[prop(into)] on_click: Callback) -> impl IntoView { view! { + } +} +``` + +The code is very similar in this case. On more advanced use-cases using a +closure might require some cloning compared to using a `Callback`. + > Note the way we declare the generic type `F` here for the callback. If you’re > confused, look back at the [generic props](./03_components.html#generic-props) section > of the chapter on components. + ## 3. Use an Event Listener You can actually write Option 2 in a slightly different way. If the callback maps directly onto diff --git a/examples/counters/rust-toolchain.toml b/examples/counters/rust-toolchain.toml new file mode 100644 index 0000000000..e9743fb495 --- /dev/null +++ b/examples/counters/rust-toolchain.toml @@ -0,0 +1,3 @@ + +[toolchain] +channel = "nightly" diff --git a/examples/login_with_token_csr_only/client/src/components/navbar.rs b/examples/login_with_token_csr_only/client/src/components/navbar.rs index df18c4c9d7..af5b4164c9 100644 --- a/examples/login_with_token_csr_only/client/src/components/navbar.rs +++ b/examples/login_with_token_csr_only/client/src/components/navbar.rs @@ -3,10 +3,10 @@ use leptos::*; use leptos_router::*; #[component] -pub fn NavBar(logged_in: Signal, on_logout: F) -> impl IntoView -where - F: Fn() + 'static + Clone, -{ +pub fn NavBar( + logged_in: Signal, + #[prop(into)] on_logout: Callback<()>, +) -> impl IntoView { view! {