pub struct ForProps<IF, I, T, EF, N, KF, K>where
IF: Fn() -> I + 'static,
I: IntoIterator<Item = T>,
EF: Fn(Scope, T) -> N + 'static,
N: IntoView,
KF: Fn(&T) -> K + 'static,
K: Eq + Hash + 'static,
T: 'static,{
pub each: IF,
pub key: KF,
pub view: EF,
}
Expand description
Props for the For
component.
Iterates over children and displays them, keyed by the key
function given.
This is much more efficient than naively iterating over nodes with .iter().map(|n| view! { cx, ... })...
,
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(cx: Scope) -> impl IntoView {
let (counters, set_counters) = create_signal::<Vec<Counter>>(cx, vec![]);
view! {
cx,
<div>
<For
// a function that returns the items we're iterating over; a signal is fine
each=counters
// a unique key for each item
key=|counter| counter.id
// renders each item to a view
view=move |cx, counter: Counter| {
view! {
cx,
<button>"Value: " {move || counter.count.get()}</button>
}
}
/>
</div>
}
}
Required Props
- cx:
Scope
- each: [
IF
]- Items over which the component should iterate.
- key: [
KF
]- A key function that will be applied to each item.
- view: [
EF
]- The view that will be displayed for each item.
Fields§
§each: IF
Items over which the component should iterate.
key: KF
A key function that will be applied to each item.
view: EF
The view that will be displayed for each item.
Implementations§
Auto Trait Implementations§
impl<IF, I, T, EF, N, KF, K> RefUnwindSafe for ForProps<IF, I, T, EF, N, KF, K>where EF: RefUnwindSafe, IF: RefUnwindSafe, KF: RefUnwindSafe,
impl<IF, I, T, EF, N, KF, K> Send for ForProps<IF, I, T, EF, N, KF, K>where EF: Send, IF: Send, KF: Send,
impl<IF, I, T, EF, N, KF, K> Sync for ForProps<IF, I, T, EF, N, KF, K>where EF: Sync, IF: Sync, KF: Sync,
impl<IF, I, T, EF, N, KF, K> Unpin for ForProps<IF, I, T, EF, N, KF, K>where EF: Unpin, IF: Unpin, KF: Unpin,
impl<IF, I, T, EF, N, KF, K> UnwindSafe for ForProps<IF, I, T, EF, N, KF, K>where EF: UnwindSafe, IF: UnwindSafe, KF: UnwindSafe,
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