Add a warning when a copy value is used in a higher scope than it was created in (#2771)

This commit is contained in:
Evan Almloff authored and GitHub committed 2024-08-02 10:48:13 -07:00
1 parent 0acfe37398
commit 14081e7e45
9 files changed
+289 -115

No files matched your search

+32
View File
@@ -0,0 +1,32 @@
#[component]
fn Counters() -> Element {
let mut counts = use_signal(Vec::new);
rsx! {
button { onclick: move |_| counts.write().push(0), "Add child" }
button {
onclick: move |_| {
counts.write().pop();
},
"Remove child"
}
"{counts:?}"
// Instead of passing up a signal, we can just write to the signal that lives in the parent
for index in 0..counts.len() {
Counter {
index,
counts
}
}
}
}
#[component]
fn Counter(index: usize, mut counts: Signal<Vec<i32>>) -> Element {
rsx! {
button {
onclick: move |_| counts.write()[index] += 1,
"{counts.read()[index]}"
}
}
}