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. // Form component for adding new items.
<ItemForm on_submit=Box::new(add_item) /> <ItemForm on_submit=Box::new(add_item) />
// Component to display the list of items. // Component to display the list of items.
<ItemsList items=items_signal.get() /> <ItemsList items=items_signal />
</div> </div>
} }
} }

View File

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