-
Is your feature request related to a problem? Please describe. Example #[component]
fn MyComponent(cx: Scope, list: Signal<Option<Vec<DataItem>>>) -> impl IntoView {
view!{cx,
<Suspense fallback=move || view!{cx, <p>{"Loading..."}</p>}>
{move || {
list.map(|list| {
view!{cx,
<For
each = move || list.clone()
key = move |item| item.key
view = move |cx, item| view!{cx, <Item item=item />}
/>
}
})
}}
</Suspense>
}
} If I understand reactivity correctly, then the signal will trigger on every change to the list, which will cause the whole Describe the solution you'd like |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
Converting this to a discussion since, as you say, it's more of a question than a feature request. Here's an example. Adding a #[server(SomeData, "/api")]
pub async fn some_data(len: usize) -> Result<Vec<usize>, ServerFnError> {
Ok((0..len).collect())
}
#[component]
pub fn App(cx: Scope) -> impl IntoView {
let (count, set_count) = create_signal(cx, 3);
let data = create_resource(cx, count, some_data);
view! { cx,
<button on:click=move |_| set_count.update(|n| *n += 1)>"+1"</button>
<MyComponent data/>
}
}
#[component]
fn MyComponent(
cx: Scope,
data: Resource<usize, Result<Vec<usize>, ServerFnError>>,
) -> impl IntoView {
let list = Signal::derive(cx, move || data.read(cx).and_then(|n| n.ok()));
view! {cx,
<Suspense fallback=move || view!{cx, <p>{"Loading..."}</p>}>
{move || {
view!{cx,
<For
each = move || list().unwrap_or_default()
key = move |item| *item
view = move |cx, item| {
log!("rendering {item}");
view!{cx, <p>{item}</p> }
}
/>
}
}}
</Suspense>
}
} |
Beta Was this translation helpful? Give feedback.
Converting this to a discussion since, as you say, it's more of a question than a feature request.
Here's an example. Adding a
log
to the view function is useful as it will show you exactly when it rerenders. Using this simple version of your example, I demonstrated to myself that each row is only rendered once.