From c2dd963d86ef745a260d311978866f8f0bdcbfcb Mon Sep 17 00:00:00 2001 From: Antonio Curavalea <112291302+arqalite@users.noreply.github.com> Date: Tue, 4 Apr 2023 05:12:52 +0300 Subject: [PATCH] doc: fermi: add counter example to readme (#931) * doc: add counter example to readme * doc: fermi: revert use_read --- packages/fermi/README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/fermi/README.md b/packages/fermi/README.md index bd7d38ac4..f04ec5961 100644 --- a/packages/fermi/README.md +++ b/packages/fermi/README.md @@ -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 = |_| 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