examples: update to new usestate

This commit is contained in:
Jonathan Kelley 2022-03-05 15:59:35 -05:00
parent 35b22923b2
commit 398ebcf283
2 changed files with 12 additions and 15 deletions

View file

@ -16,9 +16,9 @@ pub struct Client {
fn app(cx: Scope) -> Element { fn app(cx: Scope) -> Element {
let clients = use_ref(&cx, || vec![] as Vec<Client>); let clients = use_ref(&cx, || vec![] as Vec<Client>);
let (firstname, set_firstname) = use_state(&cx, String::new); let firstname = use_state(&cx, String::new);
let (lastname, set_lastname) = use_state(&cx, String::new); let lastname = use_state(&cx, String::new);
let (description, set_description) = use_state(&cx, String::new); let description = use_state(&cx, String::new);
cx.render(rsx!( cx.render(rsx!(
body { body {
@ -55,32 +55,32 @@ fn app(cx: Scope) -> Element {
class: "new-client firstname", class: "new-client firstname",
placeholder: "First name", placeholder: "First name",
value: "{firstname}", value: "{firstname}",
oninput: move |e| set_firstname(e.value.clone()) oninput: move |e| firstname.set(e.value.clone())
} }
input { input {
class: "new-client lastname", class: "new-client lastname",
placeholder: "Last name", placeholder: "Last name",
value: "{lastname}", value: "{lastname}",
oninput: move |e| set_lastname(e.value.clone()) oninput: move |e| lastname.set(e.value.clone())
} }
textarea { textarea {
class: "new-client description", class: "new-client description",
placeholder: "Description", placeholder: "Description",
value: "{description}", value: "{description}",
oninput: move |e| set_description(e.value.clone()) oninput: move |e| description.set(e.value.clone())
} }
} }
button { button {
class: "pure-button pure-button-primary", class: "pure-button pure-button-primary",
onclick: move |_| { onclick: move |_| {
clients.write().push(Client { clients.write().push(Client {
description: (*description).clone(), description: (**description).clone(),
first_name: (*firstname).clone(), first_name: (**firstname).clone(),
last_name: (*lastname).clone(), last_name: (**lastname).clone(),
}); });
set_description(String::new()); description.set(String::new());
set_firstname(String::new()); firstname.set(String::new());
set_lastname(String::new()); lastname.set(String::new());
}, },
"Add New" "Add New"
} }

View file

@ -1,7 +1,4 @@
use dioxus::prelude::*; use dioxus::prelude::*;
use dioxus::router::*;
use dioxus::desktop::tao::dpi::LogicalSize; use dioxus::desktop::tao::dpi::LogicalSize;
fn main() { fn main() {