浏览代码

doc: fermi: add counter example to readme (#931)

* doc: add counter example to readme

* doc: fermi: revert use_read
Antonio Curavalea 2 年之前
父节点
当前提交
c2dd963d86
共有 1 个文件被更改,包括 20 次插入0 次删除
  1. 20 0
      packages/fermi/README.md

+ 20 - 0
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<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