From fe3577faaf97e3da7e29ec2b01b14c1f8fa0d56f Mon Sep 17 00:00:00 2001 From: YuKun Liu <41265098+mrxiaozhuox@users.noreply.github.com> Date: Mon, 28 Mar 2022 10:42:09 +0800 Subject: [PATCH 1/2] fix: `usestate` docs --- packages/hooks/src/usestate.rs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/hooks/src/usestate.rs b/packages/hooks/src/usestate.rs index 68612aca1..60dc172b3 100644 --- a/packages/hooks/src/usestate.rs +++ b/packages/hooks/src/usestate.rs @@ -92,9 +92,9 @@ impl UseState { /// /// ```rust, ignore /// fn component(cx: Scope) -> Element { - /// let (count, set_count) = use_state(&cx, || 0); + /// let count = use_state(&cx, || 0); /// cx.spawn({ - /// let set_count = set_count.to_owned(); + /// let set_count = count.to_owned(); /// async move { /// let current = set_count.current(); /// } @@ -119,11 +119,11 @@ impl UseState { /// /// ```rust, ignore /// fn component(cx: Scope) -> Element { - /// let (value, set_value) = use_state(&cx, || 0); + /// let value = use_state(&cx, || 0); /// /// rsx!{ /// Component { - /// handler: set_val.setter() + /// handler: value.setter() /// } /// } /// } @@ -144,16 +144,16 @@ impl UseState { /// # use dioxus_core::prelude::*; /// # use dioxus_hooks::*; /// fn component(cx: Scope) -> Element { - /// let (value, set_value) = use_state(&cx, || 0); + /// let value = use_state(&cx, || 0); /// /// // to increment the value - /// set_value.modify(|v| v + 1); + /// value.modify(|v| v + 1); /// /// // usage in async /// cx.spawn({ - /// let set_value = set_value.to_owned(); + /// let value = value.to_owned(); /// async move { - /// set_value.modify(|v| v + 1); + /// value.modify(|v| v + 1); /// } /// }); /// @@ -185,9 +185,9 @@ impl UseState { /// # use dioxus_core::prelude::*; /// # use dioxus_hooks::*; /// fn component(cx: Scope) -> Element { - /// let (value, set_value) = use_state(&cx, || 0); + /// let value = use_state(&cx, || 0); /// - /// let as_rc = set_value.get(); + /// let as_rc = value.get(); /// assert_eq!(as_rc.as_ref(), &0); /// /// # todo!() @@ -207,12 +207,12 @@ impl UseState { /// /// ```rust, ignore /// fn component(cx: Scope) -> Element { - /// let (count, set_count) = use_state(&cx, || 0); + /// let count = use_state(&cx, || 0); /// cx.spawn({ - /// let set_count = set_count.to_owned(); + /// let count = count.to_owned(); /// async move { /// // for the component to re-render - /// set_count.needs_update(); + /// count.needs_update(); /// } /// }) /// } @@ -237,9 +237,9 @@ impl UseState { /// # Examples /// /// ``` - /// let (val, set_val) = use_state(&cx, || 0); + /// let val = use_state(&cx, || 0); /// - /// set_val.with_mut(|v| *v = 1); + /// val.with_mut(|v| *v = 1); /// ``` pub fn with_mut(&self, apply: impl FnOnce(&mut T)) { let mut slot = self.slot.borrow_mut(); @@ -269,9 +269,9 @@ impl UseState { /// # Examples /// /// ``` - /// let (val, set_val) = use_state(&cx, || 0); + /// let val = use_state(&cx, || 0); /// - /// *set_val.make_mut() += 1; + /// *val.make_mut() += 1; /// ``` #[must_use] pub fn make_mut(&self) -> RefMut { From 8e1e06d8c3648994d4c77d1174241c95901a597e Mon Sep 17 00:00:00 2001 From: YuKun Liu Date: Mon, 28 Mar 2022 13:11:33 +0800 Subject: [PATCH 2/2] fix: docs --- docs/guide/src/interactivity/useref.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/guide/src/interactivity/useref.md b/docs/guide/src/interactivity/useref.md index 15b85dcf5..e8eda8e83 100644 --- a/docs/guide/src/interactivity/useref.md +++ b/docs/guide/src/interactivity/useref.md @@ -60,9 +60,9 @@ The best use case of `use_ref` is to manage "complex" data local to your compone ```rust -let val = use_state(&cx, || vec![1, 3, 3, 7]); -let val = use_state(&cx, || (0..10000).collect::x>()); -let val = use_state(&cx, || Configuration { +let val = use_ref(&cx, || vec![1, 3, 3, 7]); +let val = use_ref(&cx, || (0..10000).collect::x>()); +let val = use_ref(&cx, || Configuration { a: "asdasd", // .. more complex fields }); @@ -82,6 +82,7 @@ fn app(cx: Scope) -> Element { }) } +#[inline_props] fn Child(cx: Scope, val: UseRef) -> Element { // ... }