瀏覽代碼

simplify use_dependencies docs

Evan Almloff 1 年之前
父節點
當前提交
3866aa2977
共有 3 個文件被更改,包括 8 次插入27 次删除
  1. 4 14
      packages/hooks/src/use_effect.rs
  2. 2 11
      packages/hooks/src/use_resource.rs
  3. 2 2
      packages/signals/src/memo.rs

+ 4 - 14
packages/hooks/src/use_effect.rs

@@ -65,23 +65,13 @@ impl Effect {
     ///
     /// #[component]
     /// fn Comp(delay: u32) -> Element {
-    ///     // Because the resource subscribes to `delay` by adding it as a dependency, the effect's closure will rerun every time `delay` changes.
-    ///     let current_weather = use_resource(move || async move {
-    ///         sleep(delay).await;
-    ///         "Sunny"
+    ///     // Because the effect subscribes to `delay` by adding it as a dependency, the effect's closure will rerun every time `delay` changes.
+    ///     use_effect(move || {
+    ///         println!("It is safe to manually manipulate the dom here");
     ///     })
     ///     .use_dependencies((&delay,));
     ///
-    ///     rsx! {
-    ///         // the value of the resource can be polled to
-    ///         // conditionally render elements based off if it's future
-    ///         // finished (Some(Ok(_)), errored Some(Err(_)),
-    ///         // or is still running (None)
-    ///         match &*current_weather.read_unchecked() {
-    ///             Some(weather) => rsx! { "{weather}" },
-    ///             None =>  rsx! { p { "Loading..." } }
-    ///         }
-    ///     }
+    ///     todo!()
     /// }
     /// ```
     pub fn use_dependencies(mut self, dependency: impl Dependency) -> Self {

+ 2 - 11
packages/hooks/src/use_resource.rs

@@ -23,7 +23,7 @@ use std::{cell::Cell, future::Future, rc::Rc};
 ///    });
 ///
 ///    // Because the resource's future subscribes to `country` by reading it (`country.read()`),
-///    // everytime `country` changes the resource's future will run again and thus provide a new value.
+///    // every time `country` changes the resource's future will run again and thus provide a new value.
 ///    let current_weather = use_resource(move || async move { get_weather(&country.read().clone()).await });
 ///    
 ///    rsx! {
@@ -144,16 +144,7 @@ impl<T> Resource<T> {
     ///     })
     ///     .use_dependencies((&delay,));
     ///
-    ///     rsx! {
-    ///         // the value of the resource can be polled to
-    ///         // conditionally render elements based off if it's future
-    ///         // finished (Some(Ok(_)), errored Some(Err(_)),
-    ///         // or is still running (None)
-    ///         match &*current_weather.read_unchecked() {
-    ///             Some(weather) => rsx! { "{weather}" },
-    ///             None =>  rsx! { p { "Loading..." } }
-    ///         }
-    ///     }
+    ///     todo!()
     /// }
     /// ```
     pub fn use_dependencies(mut self, dependency: impl Dependency) -> Self {

+ 2 - 2
packages/signals/src/memo.rs

@@ -166,8 +166,8 @@ impl<T: 'static> Memo<T> {
     ///
     /// #[component]
     /// fn Comp(count: u32) -> Element {
-    ///     // Because the resource subscribes to `delay` by adding it as a dependency, the memo will rerun every time `count` changes.
-    ///     let new_count = use_memo(move || async move {
+    ///     // Because the memo subscribes to `count` by adding it as a dependency, the memo will rerun every time `count` changes.
+    ///     let new_count = use_memo(move || {
     ///         count + 1
     ///     })
     ///     .use_dependencies((&count,));