simplify use_dependencies docs

This commit is contained in:
Evan Almloff 2024-03-13 10:03:00 -05:00
parent 0951a389f7
commit 3866aa2977
3 changed files with 8 additions and 27 deletions

View file

@ -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 {

View file

@ -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 {

View file

@ -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,));