From d3b9b764e09610d1eb3b86524209fc0a8a868299 Mon Sep 17 00:00:00 2001 From: marc2332 Date: Mon, 26 Feb 2024 21:46:00 +0100 Subject: [PATCH 1/2] fix: Update `dioxus-router` docs --- packages/router/src/hooks/use_navigator.rs | 4 ++-- packages/router/src/hooks/use_route.rs | 8 ++------ packages/router/src/utils/use_router_internal.rs | 4 ++-- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/packages/router/src/hooks/use_navigator.rs b/packages/router/src/hooks/use_navigator.rs index 57a3bd3b8e..1207b1fb28 100644 --- a/packages/router/src/hooks/use_navigator.rs +++ b/packages/router/src/hooks/use_navigator.rs @@ -2,7 +2,7 @@ use dioxus_lib::prelude::{try_consume_context, use_hook}; use crate::prelude::{Navigator, RouterContext}; -/// A hook that provides access to the navigator to change the router history. Unlike [`use_router`], this hook will not cause a rerender when the current route changes +/// A hook that provides access to the navigator to change the router history. /// /// > The Routable macro will define a version of this hook with an explicit type. /// @@ -26,7 +26,7 @@ use crate::prelude::{Navigator, RouterContext}; /// /// #[component] /// fn Index() -> Element { -/// let navigator = use_navigator(&cx); +/// let navigator = use_navigator(); /// /// rsx! { /// button { diff --git a/packages/router/src/hooks/use_route.rs b/packages/router/src/hooks/use_route.rs index 7a9942bd17..d0c66ebfb4 100644 --- a/packages/router/src/hooks/use_route.rs +++ b/packages/router/src/hooks/use_route.rs @@ -5,12 +5,8 @@ use crate::utils::use_router_internal::use_router_internal; /// /// > The Routable macro will define a version of this hook with an explicit type. /// -/// # Return values -/// - None, when not called inside a [`Link`] component. -/// - Otherwise the current route. -/// /// # Panic -/// - When the calling component is not nested within a [`Link`] component during a debug build. +/// - When the calling component is not nested within a [`Router`] component. /// /// # Example /// ```rust @@ -49,7 +45,7 @@ pub fn use_route() -> R { match use_router_internal() { Some(r) => r.current(), None => { - panic!("`use_route` must have access to a parent router") + panic!("`use_route` must be called in a descendant of a Router component") } } } diff --git a/packages/router/src/utils/use_router_internal.rs b/packages/router/src/utils/use_router_internal.rs index 441063cbe9..04853233ce 100644 --- a/packages/router/src/utils/use_router_internal.rs +++ b/packages/router/src/utils/use_router_internal.rs @@ -8,10 +8,10 @@ use crate::prelude::*; /// single component, but not recommended. Multiple subscriptions will be discarded. /// /// # Return values -/// - [`None`], when the current component isn't a descendant of a [`Link`] component. +/// - [`None`], when the current component isn't a descendant of a [`Router`] component. /// - Otherwise [`Some`]. pub(crate) fn use_router_internal() -> Option { - let router = use_hook(consume_context::); + let router = try_consume_context::()?; let id = current_scope_id().expect("use_router_internal called outside of a component"); use_drop({ to_owned![router]; From 97478bcb13eeeb6f8f9287113a6196997e59b207 Mon Sep 17 00:00:00 2001 From: marc2332 Date: Mon, 26 Feb 2024 21:50:16 +0100 Subject: [PATCH 2/2] fix unrelated to dioxus-router --- packages/core-macro/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core-macro/src/lib.rs b/packages/core-macro/src/lib.rs index a4626b65af..a469eb04c1 100644 --- a/packages/core-macro/src/lib.rs +++ b/packages/core-macro/src/lib.rs @@ -167,7 +167,7 @@ pub(crate) const COMPONENT_ARG_CASE_CHECK_OFF: &str = "no_case_check"; /// #[warn(non_snake_case)] /// #[inline(always)] /// fn __dx_inner_comp(props: GreetPersonProps>e) -> Element { -/// let GreetPersonProps { person } = &cx.props; +/// let GreetPersonProps { person } = props; /// { /// rsx! { "hello, {person}" } /// }