mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-10 14:44:12 +00:00
doc: fermi: add counter example to readme (#931)
* doc: add counter example to readme * doc: fermi: revert use_read
This commit is contained in:
parent
3aa7349db7
commit
c2dd963d86
1 changed files with 20 additions and 0 deletions
|
@ -63,6 +63,26 @@ fn NameCard(cx: Scope) -> Element {
|
|||
}
|
||||
```
|
||||
|
||||
If needed, we can update the atom's value, based on itself:
|
||||
|
||||
```rust, ignore
|
||||
static COUNT: Atom<i32> = |_| 0;
|
||||
|
||||
fn Counter(cx: Scope) -> Element {
|
||||
let mut count = use_atom_state(cx, COUNT);
|
||||
|
||||
cx.render(rsx!{
|
||||
p {
|
||||
"{count}"
|
||||
}
|
||||
button {
|
||||
onclick: move |_| count += 1,
|
||||
"Increment counter"
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
It's that simple!
|
||||
|
||||
## Installation
|
||||
|
|
Loading…
Reference in a new issue