restore readme

This commit is contained in:
Evan Almloff 2024-03-04 15:27:27 -06:00
parent fc7efd8006
commit 48f845985b

View file

@ -12,42 +12,11 @@ fn main() {
}
fn app() -> Element {
let mut vec = use_signal(|| vec![1, 2, 3]);
let len = vec.len();
println!("app len: {}", len);
use_effect(move || {
println!("app effect len: {}", vec.len());
});
let mut count = use_signal(|| 0);
rsx! {
button {
onclick: move |_| {
let mut vec = vec.write();
vec.push(len);
},
"Add"
}
button {
onclick: move |_| {
vec.pop();
},
"Remove"
}
for i in 0..len {
Child {
index: i,
vec,
}
}
}
}
#[component]
fn Child(index: usize, vec: Signal<Vec<usize>>) -> Element {
let item = use_memo(move || vec.read()[index]);
rsx! {
div { "Item: {item}" }
h1 { "High-Five counter: {count}" }
button { onclick: move |_| count += 1, "Up high!" }
button { onclick: move |_| count -= 1, "Down low!" }
}
}