Function Keyed
pub fn Keyed<T, K, U, List, F, Key>(
props: KeyedProps<T, K, U, List, F, Key>,
) -> View
Expand description
Keyed iteration.
Use this instead of directly rendering an array of View
s.
Using this will minimize re-renders instead of re-rendering every view node on every
state change.
For non keyed iteration, see Indexed
.
ยงExample
#[derive(Clone, PartialEq)]
struct AnimalInfo {
// The name of the animal.
name: &'static str,
// An unique id to identify the animal.
id: u32,
}
let animals = create_signal(vec![
AnimalInfo { name: "Dog", id: 1 },
AnimalInfo { name: "Cat", id: 2 },
AnimalInfo { name: "Fish", id: 3 },
]);
view! {
ul {
Keyed(
list=animals,
view=|animal| view! {
li { (animal.name) }
},
key=|animal| animal.id,
)
}
}