use implicit_clone::unsync::*; use wasm_bindgen::{JsCast, UnwrapThrowExt}; use web_sys::{HtmlInputElement, KeyboardEvent}; use yew::prelude::*; #[derive(Properties, PartialEq)] struct FolksViewProps { folks: IArray, } #[function_component(FolksView)] fn folks_view(props: &FolksViewProps) -> Html { html! { <>

{"Hello to:"}

} } #[function_component(ArrayExample)] pub fn array_example() -> Html { let folks = use_state(IArray::::default); let onkeyup = { let folks = folks.clone(); Callback::from(move |e: KeyboardEvent| { if e.key() == "Enter" { let event: Event = e.dyn_into().unwrap_throw(); let event_target = event.target().unwrap_throw(); let target: HtmlInputElement = event_target.dyn_into().unwrap_throw(); let name = target.value(); target.set_value(""); folks.set( folks .iter() .chain(std::iter::once(IString::from(name))) .collect(), ); } }) }; html! { <>

{"Input"}

{"Output"}

} }