From 5a73147d69be36368d92c79f0643124c15b2aa6a Mon Sep 17 00:00:00 2001 From: andrey Date: Tue, 27 Feb 2024 10:36:05 +0800 Subject: [PATCH] added better documentation and code snipppets for the use_resource, use_future, use_effect and use_context hooks --- packages/hooks/src/use_context.rs | 7 +++++-- packages/hooks/src/use_effect.rs | 2 +- packages/hooks/src/use_future.rs | 8 ++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/hooks/src/use_context.rs b/packages/hooks/src/use_context.rs index 5deafd417..27c586e4f 100644 --- a/packages/hooks/src/use_context.rs +++ b/packages/hooks/src/use_context.rs @@ -45,8 +45,11 @@ pub fn use_context() -> T { // This component does read from the signal, so when the signal changes it will rerun ///#[component] ///fn Child() -> Element { -/// let signal: Signal = use_context(); -/// rsx! { "{signal}" } +/// let signal: Signal = use_context(); +/// rsx! { +/// button { onclick: move |_| signal += 1, "increment context" } +/// p {"{signal}"} +/// } ///} /// ``` pub fn use_context_provider(f: impl FnOnce() -> T) -> T { diff --git a/packages/hooks/src/use_effect.rs b/packages/hooks/src/use_effect.rs index 97a603b21..0028bc7c5 100644 --- a/packages/hooks/src/use_effect.rs +++ b/packages/hooks/src/use_effect.rs @@ -1,7 +1,7 @@ use dioxus_core::prelude::*; use dioxus_signals::ReactiveContext; -/// use_effect will subscribe to any changes in the signal values it captures +/// `use_effect` will subscribe to any changes in the signal values it captures /// effects will always run after first mount and then whenever the signal values change /// If the use_effect call was skipped due to an early return, the effect will no longer activate. /// ```rust diff --git a/packages/hooks/src/use_future.rs b/packages/hooks/src/use_future.rs index d2619f624..a4f6ed214 100644 --- a/packages/hooks/src/use_future.rs +++ b/packages/hooks/src/use_future.rs @@ -8,17 +8,17 @@ use dioxus_signals::*; use dioxus_signals::{Readable, Writable}; use std::future::Future; -/// A hook that allows you to spawn a future -/// +/// A hook that allows you to spawn a future. +/// This future will **not** run on the server /// The future is spawned on the next call to `flush_sync` which means that it will not run on the server. /// To run a future on the server, you should use `spawn` directly. -/// use_future assumes your future will never complete - **it won't return a value**. +/// `use_future` assumes your future will never complete - **it won't return a value**. /// If you want to return a value, use `use_resource` instead. /// ```rust /// fn app() -> Element { /// let mut count = use_signal(|| 0); /// let mut running = use_signal(|| true); -/// // use_future will spawn an infinitely running future that can be started and stopped +/// // `use_future` will spawn an infinitely running future that can be started and stopped /// use_future(move || async move { /// loop { /// if running() {