Merge pull request #336 from mrxiaozhuox/master

Fixed Docs Problem
This commit is contained in:
Jon Kelley 2022-03-28 11:05:01 -04:00 committed by GitHub
commit 3a467ec745
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 20 deletions

View file

@ -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::<Vec<_>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::<Vec<_>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<i32>) -> Element {
// ...
}

View file

@ -92,9 +92,9 @@ impl<T: 'static> UseState<T> {
///
/// ```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<T: 'static> UseState<T> {
///
/// ```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<T: 'static> UseState<T> {
/// # 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<T: 'static> UseState<T> {
/// # 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<T: 'static> UseState<T> {
///
/// ```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<T: Clone> UseState<T> {
/// # 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<T: Clone> UseState<T> {
/// # 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<T> {