fix signal readme example
This commit is contained in:
1 parent
292b3367dd
commit
e2c08a79ae
2 files changed
+17
-5
No files matched your search
@@ -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.
|
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
|
```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());
|
let signal = use_signal(cx, || "hello world".to_string());
|
||||||
|
|
||||||
spawn(async move {
|
spawn(async move {
|
||||||
// signal is Copy even though String is not copy
|
// signal is Copy even though String is not copy
|
||||||
signal
|
print!("{signal}");
|
||||||
});
|
});
|
||||||
|
|
||||||
render! {
|
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.
|
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
|
```rust
|
||||||
|
use dioxus::prelude::*;
|
||||||
|
use dioxus_signals::*;
|
||||||
|
|
||||||
fn app(cx: Scope) -> Element {
|
fn app(cx: Scope) -> Element {
|
||||||
// Because signal is never read in this component, this component will not rerun when the signal changes
|
// Because signal is never read in this component, this component will not rerun when the signal changes
|
||||||
let signal = use_signal(cx, || 0);
|
let signal = use_signal(cx, || 0);
|
||||||
|
|
||||||
render! {
|
render! {
|
||||||
onclick: move |_| {
|
button {
|
||||||
*signal.write() += 1;
|
onclick: move |_| {
|
||||||
|
*signal.write() += 1;
|
||||||
|
},
|
||||||
|
"Increase"
|
||||||
}
|
}
|
||||||
for id in 0..10 {
|
for id in 0..10 {
|
||||||
Child {
|
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:
|
Because subscriptions happen when you read from (not create) the data, you can provide signals through the normal context API:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
use dioxus::prelude::*;
|
||||||
|
use dioxus_signals::*;
|
||||||
|
|
||||||
fn app(cx: Scope) -> Element {
|
fn app(cx: Scope) -> Element {
|
||||||
// Because signal is never read in this component, this component will not rerun when the signal changes
|
// Because signal is never read in this component, this component will not rerun when the signal changes
|
||||||
use_context_provider(cx, || Signal::new(0));
|
use_context_provider(cx, || Signal::new(0));
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#![allow(non_snake_case)]
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
use dioxus_signals::{use_signal, Effect, Signal};
|
use dioxus_signals::Signal;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
dioxus_desktop::launch(app);
|
dioxus_desktop::launch(app);
|
||||||
|
|||||||
Reference in new issue
Block a user