pub struct ForEnumerateProps<IF, I, T, EF, N, KF, K>{
pub each: IF,
pub key: KF,
pub children: EF,
}Expand description
Props for the ForEnumerate component.
Iterates over children and displays them, keyed by the key function given.
Compared with For, it has an additional index parameter, which can be used to obtain the current index in real time.
This is much more efficient than naively iterating over nodes with .iter().map(|n| view! { ... })...,
as it avoids re-creating DOM nodes that are not being changed.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
struct Counter {
id: usize,
count: RwSignal<i32>
}
#[component]
fn Counters() -> impl IntoView {
let (counters, set_counters) = create_signal::<Vec<Counter>>(vec![]);
view! {
<div>
<ForEnumerate
// a function that returns the items we're iterating over; a signal is fine
each=move || counters.get()
// a unique key for each item
key=|counter| counter.id
// renders each item to a view
children={move |index: ReadSignal<usize>, counter: Counter| {
view! {
<button>{move || index.get()} ". Value: " {move || counter.count.get()}</button>
}
}}
/>
</div>
}
}§Required Props
- each: [
IF]- Items over which the component should iterate.
- key: [
KF]- A key function that will be applied to each item.
- children: [
EF]- A function that takes the index and the item, and returns the view that will be displayed for each item.
Fields§
§each: IFItems over which the component should iterate.
key: KFA key function that will be applied to each item.
children: EFA function that takes the index and the item, and returns the view that will be displayed for each item.
Implementations§
Source§impl<IF, I, T, EF, N, KF, K> ForEnumerateProps<IF, I, T, EF, N, KF, K>
impl<IF, I, T, EF, N, KF, K> ForEnumerateProps<IF, I, T, EF, N, KF, K>
Trait Implementations§
Source§impl<IF, I, T, EF, N, KF, K> Props for ForEnumerateProps<IF, I, T, EF, N, KF, K>
impl<IF, I, T, EF, N, KF, K> Props for ForEnumerateProps<IF, I, T, EF, N, KF, K>
Auto Trait Implementations§
impl<IF, I, T, EF, N, KF, K> Freeze for ForEnumerateProps<IF, I, T, EF, N, KF, K>
impl<IF, I, T, EF, N, KF, K> RefUnwindSafe for ForEnumerateProps<IF, I, T, EF, N, KF, K>
impl<IF, I, T, EF, N, KF, K> Send for ForEnumerateProps<IF, I, T, EF, N, KF, K>
impl<IF, I, T, EF, N, KF, K> Sync for ForEnumerateProps<IF, I, T, EF, N, KF, K>
impl<IF, I, T, EF, N, KF, K> Unpin for ForEnumerateProps<IF, I, T, EF, N, KF, K>
impl<IF, I, T, EF, N, KF, K> UnwindSafe for ForEnumerateProps<IF, I, T, EF, N, KF, K>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> SerializableKey for T
impl<T> SerializableKey for T
Source§impl<T> StorageAccess<T> for T
impl<T> StorageAccess<T> for T
Source§fn as_borrowed(&self) -> &T
fn as_borrowed(&self) -> &T
Borrows the value.
Source§fn into_taken(self) -> T
fn into_taken(self) -> T
Takes the value.