/
germanubis
/
yew
Обзор
Документация
Войти
/
germanubis
/
yew
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/immutable/src/array.rs
55 строк
1 KB
dependabot[bot]
Bump the cargo-deps group across 1 directory with 18 updates (#3933)
22 окт 2025, 20:36
Не верифицирован
22 окт 2025, 20:36
71e24b7
Код
Авторство
О чём код?
use implicit_clone::unsync::*; use wasm_bindgen::{JsCast, UnwrapThrowExt}; use web_sys::{HtmlInputElement, KeyboardEvent}; use yew::prelude::*; #[derive(Properties, PartialEq)] struct FolksViewProps { folks: IArray<IString>, } #[function_component(FolksView)] fn folks_view(props: &FolksViewProps) -> Html { html! { <> <p>{"Hello to:"}</p> <ul> { for props.folks.iter().map(|s| html!(<li>{s}</li>)) } </ul> </> } } #[function_component(ArrayExample)] pub fn array_example() -> Html { let folks = use_state(IArray::<IString>::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() .cloned() .chain(std::iter::once(IString::from(name))) .collect(), ); } }) }; html! { <> <h2>{"Input"}</h2> <input {onkeyup} /> <h2>{"Output"}</h2> <FolksView folks={&*folks} /> </> } }