fix(app): enhance signal management in App component

- Switched from `create_signal` to a tuple-based signal declaration using `(items_signal, set_items)` for improved clarity.
- Replaced `items.update` with a closure-based update approach for `set_items`.
- Added `Box::new` to `ItemForm`'s `on_submit` to properly handle the function's lifetime and scope.
- Removed unused imports for `leptos_meta` and `leptos_router` to clean up the code.
This commit is contained in:
Ryan Mwangi 2024-12-09 13:56:39 +03:00
parent de6559e5e4
commit fca8c6fa2f
1 changed files with 4 additions and 7 deletions

View File

@ -1,16 +1,13 @@
use leptos::*;
use leptos_meta::*;
use leptos_router::*;
use crate::components::{item_form::ItemForm, items_list::ItemsList};
use crate::models::item::Item;
use std::sync::Arc;
#[component]
pub fn App() -> impl IntoView {
let items = create_signal(Vec::<Item>::new());
let (items_signal, set_items) = create_signal(Vec::<Item>::new());
let add_item = move |name: String, description: String, tags: Vec<(String, String)>| {
items.update(|items| {
set_items;(|mut items: Vec<Item>| {
items.push(Item {
id: uuid::Uuid::new_v4().to_string(),
name,
@ -23,8 +20,8 @@ pub fn App() -> impl IntoView {
view! {
<div>
<h1>CompareWare</h1>
<ItemForm on_submit=add_item />
<ItemsList items=items.get().clone() />
<ItemForm on_submit=Box::new(add_item) />
<ItemsList items={items_signal.get().clone()} />
</div>
}
}