mirror of
https://github.com/DioxusLabs/dioxus
synced 2025-02-22 00:28:28 +00:00
added better documentation and code snipppets for the use_resource, use_future, use_effect and use_context hooks
This commit is contained in:
parent
24ebc1e628
commit
5a73147d69
3 changed files with 10 additions and 7 deletions
packages/hooks/src
|
@ -45,8 +45,11 @@ pub fn use_context<T: 'static + Clone>() -> T {
|
|||
// This component does read from the signal, so when the signal changes it will rerun
|
||||
///#[component]
|
||||
///fn Child() -> Element {
|
||||
/// let signal: Signal<i32> = use_context();
|
||||
/// rsx! { "{signal}" }
|
||||
/// let signal: Signal<i32> = use_context();
|
||||
/// rsx! {
|
||||
/// button { onclick: move |_| signal += 1, "increment context" }
|
||||
/// p {"{signal}"}
|
||||
/// }
|
||||
///}
|
||||
/// ```
|
||||
pub fn use_context_provider<T: 'static + Clone>(f: impl FnOnce() -> T) -> T {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Add table
Reference in a new issue