diff --git a/packages/signals/README.md b/packages/signals/README.md index 68cb8d80a..baac37867 100644 --- a/packages/signals/README.md +++ b/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) -> 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)); diff --git a/packages/signals/examples/context.rs b/packages/signals/examples/context.rs index ddd52e691..5e7ea831f 100644 --- a/packages/signals/examples/context.rs +++ b/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);