Browse Source

fix signal readme example

Evan Almloff 1 năm trước cách đây
mục cha
commit
e2c08a79ae
2 tập tin đã thay đổi với 17 bổ sung5 xóa
  1. 16 4
      packages/signals/README.md
  2. 1 1
      packages/signals/examples/context.rs

+ 16 - 4
packages/signals/README.md

@@ -7,12 +7,15 @@ Dioxus Signals is an ergonomic Copy runtime for data with local subscriptions in
 All signals implement Copy, even if the inner value does not implement copy. This makes it easy to move any data into futures or children.
 
 ```rust
-fn App(cx: Scope) -> Element {
+use dioxus::prelude::*;
+use dioxus_signals::*;
+
+fn app(cx: Scope) -> Element {
     let signal = use_signal(cx, || "hello world".to_string());
 
     spawn(async move {
         // signal is Copy even though String is not copy
-        signal
+        print!("{signal}");
     });
 
     render! {
@@ -26,13 +29,19 @@ fn App(cx: Scope) -> Element {
 Signals will only subscribe to components when you read from the signal in that component. It will never subscribe to a component when reading data in a future or event handler.
 
 ```rust
+use dioxus::prelude::*;
+use dioxus_signals::*;
+
 fn app(cx: Scope) -> Element {
     // Because signal is never read in this component, this component will not rerun when the signal changes
     let signal = use_signal(cx, || 0);
 
     render! {
-        onclick: move |_| {
-            *signal.write() += 1;
+        button {
+            onclick: move |_| {
+                *signal.write() += 1;
+            },
+            "Increase"
         }
         for id in 0..10 {
             Child {
@@ -58,6 +67,9 @@ fn Child(cx: Scope<ChildProps>) -> Element {
 Because subscriptions happen when you read from (not create) the data, you can provide signals through the normal context API:
 
 ```rust
+use dioxus::prelude::*;
+use dioxus_signals::*;
+
 fn app(cx: Scope) -> Element {
     // Because signal is never read in this component, this component will not rerun when the signal changes
     use_context_provider(cx, || Signal::new(0));

+ 1 - 1
packages/signals/examples/context.rs

@@ -1,7 +1,7 @@
 #![allow(non_snake_case)]
 
 use dioxus::prelude::*;
-use dioxus_signals::{use_signal, Effect, Signal};
+use dioxus_signals::Signal;
 
 fn main() {
     dioxus_desktop::launch(app);