mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-10 06:34:20 +00:00
Fix for Counters sample code in README (#2209)
* Fix for Counters sample code in README.md Fix for Counters sample code in README. It was throwing syntax errors. * Update README.md Fix * slightly simplify counter example with the writable vec extension trait --------- Co-authored-by: Evan Almloff <evanalmloff@gmail.com>
This commit is contained in:
parent
ffe02b43c5
commit
57e05dcf3a
1 changed files with 11 additions and 10 deletions
21
README.md
21
README.md
|
@ -254,19 +254,19 @@ Leptos is a library for building fullstack web-apps, similar to SolidJS and Soli
|
|||
|
||||
```rust
|
||||
fn Counters() -> Element {
|
||||
let mut counters = use_signal(|| vec![0; initial_length]);
|
||||
let mut counters = use_signal(|| vec![0; 10]);
|
||||
|
||||
rsx! {
|
||||
button { onclick: move |_| counters.push(counters.len()); "Add Counter" }
|
||||
ul {
|
||||
for idx in 0..counters.len() {
|
||||
li {
|
||||
button { onclick: move |_| counters[idx] += 1; "{counters[idx]}" }
|
||||
button { onclick: move |_| { counters.write().remove(idx); } "Remove" }
|
||||
rsx! {
|
||||
button { onclick: move |_| counters.push(counters.len()), "Add Counter" }
|
||||
ul {
|
||||
for idx in 0..counters.len() {
|
||||
li {
|
||||
button { onclick: move |_| counters.write()[idx] += 1, "{counters.index(idx)}" }
|
||||
button { onclick: move |_| { counters.remove(idx); }, "Remove" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -293,6 +293,7 @@ fn Counters() -> Element {
|
|||
</li>
|
||||
</For>
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- **`Copy` state**: Dioxus 0.1 to 0.4 relied on lifetimes to relax the rules of Rust's borrow checker. This worked well for event handlers, but struggled around async. In Dioxus 0.5, we've switched to a [`Copy` state model](https://crates.io/crates/generational-box) borrowed from Leptos.
|
||||
|
|
Loading…
Reference in a new issue