fix(item list): make item list reactive.

This commit is contained in:
Ryan Mwangi 2024-12-10 14:49:45 +03:00
parent 4137ded856
commit d9b60fb9f1
2 changed files with 3 additions and 3 deletions

View File

@ -28,7 +28,7 @@ pub fn App() -> impl IntoView {
// Form component for adding new items.
<ItemForm on_submit=Box::new(add_item) />
// Component to display the list of items.
<ItemsList items=items_signal.get() />
<ItemsList items=items_signal />
</div>
}
}

View File

@ -5,12 +5,12 @@ use leptos::*;
use crate::models::item::Item;
#[component]
pub fn ItemsList(items: Vec<Item>) -> impl IntoView {
pub fn ItemsList(items: ReadSignal<Vec<Item>>) -> impl IntoView {
view! {
<div>
<h2>{ "Items" }</h2>
<ul>
{items.iter().enumerate().map(|(i, item)| view! {
{move || items.get().iter().enumerate().map(|(i, item)| view! {
<li key={i.to_string()}>
<strong>{ item.name.clone() }</strong> - { item.description.clone() }
<ul>