Skip to content

Commit

Permalink
Merge pull request #1983 from marc2332/fix/update-dioxus-router-docs
Browse files Browse the repository at this point in the history
fix: Update `dioxus-router` docs
  • Loading branch information
jkelleyrtp authored Mar 4, 2024
2 parents 62d7974 + 97478bc commit 38a2c04
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/core-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}" }
/// }
Expand Down
4 changes: 2 additions & 2 deletions packages/router/src/hooks/use_navigator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand All @@ -26,7 +26,7 @@ use crate::prelude::{Navigator, RouterContext};
///
/// #[component]
/// fn Index() -> Element {
/// let navigator = use_navigator(&cx);
/// let navigator = use_navigator();
///
/// rsx! {
/// button {
Expand Down
8 changes: 2 additions & 6 deletions packages/router/src/hooks/use_route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -49,7 +45,7 @@ pub fn use_route<R: Routable + Clone>() -> 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")
}
}
}
4 changes: 2 additions & 2 deletions packages/router/src/utils/use_router_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RouterContext> {
let router = use_hook(consume_context::<RouterContext>);
let router = try_consume_context::<RouterContext>()?;
let id = current_scope_id().expect("use_router_internal called outside of a component");
use_drop({
to_owned![router];
Expand Down

0 comments on commit 38a2c04

Please sign in to comment.