fix: usestate docs
This commit is contained in:
1 parent
70fb493ce8
commit
fe3577faaf
1 file changed
+17
-17
@@ -92,9 +92,9 @@ impl<T: 'static> UseState<T> {
|
|||||||
///
|
///
|
||||||
/// ```rust, ignore
|
/// ```rust, ignore
|
||||||
/// fn component(cx: Scope) -> Element {
|
/// fn component(cx: Scope) -> Element {
|
||||||
/// let (count, set_count) = use_state(&cx, || 0);
|
/// let count = use_state(&cx, || 0);
|
||||||
/// cx.spawn({
|
/// cx.spawn({
|
||||||
/// let set_count = set_count.to_owned();
|
/// let set_count = count.to_owned();
|
||||||
/// async move {
|
/// async move {
|
||||||
/// let current = set_count.current();
|
/// let current = set_count.current();
|
||||||
/// }
|
/// }
|
||||||
@@ -119,11 +119,11 @@ impl<T: 'static> UseState<T> {
|
|||||||
///
|
///
|
||||||
/// ```rust, ignore
|
/// ```rust, ignore
|
||||||
/// fn component(cx: Scope) -> Element {
|
/// fn component(cx: Scope) -> Element {
|
||||||
/// let (value, set_value) = use_state(&cx, || 0);
|
/// let value = use_state(&cx, || 0);
|
||||||
///
|
///
|
||||||
/// rsx!{
|
/// rsx!{
|
||||||
/// Component {
|
/// Component {
|
||||||
/// handler: set_val.setter()
|
/// handler: value.setter()
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
@@ -144,16 +144,16 @@ impl<T: 'static> UseState<T> {
|
|||||||
/// # use dioxus_core::prelude::*;
|
/// # use dioxus_core::prelude::*;
|
||||||
/// # use dioxus_hooks::*;
|
/// # use dioxus_hooks::*;
|
||||||
/// fn component(cx: Scope) -> Element {
|
/// fn component(cx: Scope) -> Element {
|
||||||
/// let (value, set_value) = use_state(&cx, || 0);
|
/// let value = use_state(&cx, || 0);
|
||||||
///
|
///
|
||||||
/// // to increment the value
|
/// // to increment the value
|
||||||
/// set_value.modify(|v| v + 1);
|
/// value.modify(|v| v + 1);
|
||||||
///
|
///
|
||||||
/// // usage in async
|
/// // usage in async
|
||||||
/// cx.spawn({
|
/// cx.spawn({
|
||||||
/// let set_value = set_value.to_owned();
|
/// let value = value.to_owned();
|
||||||
/// async move {
|
/// async move {
|
||||||
/// set_value.modify(|v| v + 1);
|
/// value.modify(|v| v + 1);
|
||||||
/// }
|
/// }
|
||||||
/// });
|
/// });
|
||||||
///
|
///
|
||||||
@@ -185,9 +185,9 @@ impl<T: 'static> UseState<T> {
|
|||||||
/// # use dioxus_core::prelude::*;
|
/// # use dioxus_core::prelude::*;
|
||||||
/// # use dioxus_hooks::*;
|
/// # use dioxus_hooks::*;
|
||||||
/// fn component(cx: Scope) -> Element {
|
/// 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);
|
/// assert_eq!(as_rc.as_ref(), &0);
|
||||||
///
|
///
|
||||||
/// # todo!()
|
/// # todo!()
|
||||||
@@ -207,12 +207,12 @@ impl<T: 'static> UseState<T> {
|
|||||||
///
|
///
|
||||||
/// ```rust, ignore
|
/// ```rust, ignore
|
||||||
/// fn component(cx: Scope) -> Element {
|
/// fn component(cx: Scope) -> Element {
|
||||||
/// let (count, set_count) = use_state(&cx, || 0);
|
/// let count = use_state(&cx, || 0);
|
||||||
/// cx.spawn({
|
/// cx.spawn({
|
||||||
/// let set_count = set_count.to_owned();
|
/// let count = count.to_owned();
|
||||||
/// async move {
|
/// async move {
|
||||||
/// // for the component to re-render
|
/// // for the component to re-render
|
||||||
/// set_count.needs_update();
|
/// count.needs_update();
|
||||||
/// }
|
/// }
|
||||||
/// })
|
/// })
|
||||||
/// }
|
/// }
|
||||||
@@ -237,9 +237,9 @@ impl<T: Clone> UseState<T> {
|
|||||||
/// # Examples
|
/// # 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)) {
|
pub fn with_mut(&self, apply: impl FnOnce(&mut T)) {
|
||||||
let mut slot = self.slot.borrow_mut();
|
let mut slot = self.slot.borrow_mut();
|
||||||
@@ -269,9 +269,9 @@ impl<T: Clone> UseState<T> {
|
|||||||
/// # Examples
|
/// # 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]
|
#[must_use]
|
||||||
pub fn make_mut(&self) -> RefMut<T> {
|
pub fn make_mut(&self) -> RefMut<T> {
|
||||||
|
|||||||
Reference in new issue
Block a user