create some more compelling examples
This commit is contained in:
1 parent
0dc602eb32
commit
292b3367dd
6 files changed
+203
-8
No files matched your search
@@ -54,3 +54,25 @@ 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
|
||||
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));
|
||||
|
||||
render! {
|
||||
Child {}
|
||||
}
|
||||
}
|
||||
|
||||
fn Child(cx: Scope) -> Element {
|
||||
let signal: Signal<i32> = *use_context(cx).unwrap();
|
||||
// This component does read from the signal, so when the signal changes it will rerun
|
||||
render! {
|
||||
"{signal}"
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
Reference in new issue
Block a user