mirror of
https://github.com/yewstack/yew.git
synced 2025-12-08 21:26:25 +00:00
* Fix tests * Remove generics from virtual dom * Prep for degenerify * Fix examples * Remove props cloning * Fix tests
56 lines
1.3 KiB
Rust
56 lines
1.3 KiB
Rust
#![recursion_limit = "128"]
|
|
|
|
use yew::{html, Component, ComponentLink, Html, InputData, ShouldRender};
|
|
|
|
pub struct Model {
|
|
link: ComponentLink<Self>,
|
|
value: String,
|
|
}
|
|
|
|
pub enum Msg {
|
|
GotInput(String),
|
|
Clicked,
|
|
}
|
|
|
|
impl Component for Model {
|
|
type Message = Msg;
|
|
type Properties = ();
|
|
|
|
fn create(_: Self::Properties, link: ComponentLink<Self>) -> Self {
|
|
Model {
|
|
link,
|
|
value: "".into(),
|
|
}
|
|
}
|
|
|
|
fn update(&mut self, msg: Self::Message) -> ShouldRender {
|
|
match msg {
|
|
Msg::GotInput(new_value) => {
|
|
self.value = new_value;
|
|
}
|
|
Msg::Clicked => {
|
|
self.value = "blah blah blah".to_string();
|
|
}
|
|
}
|
|
true
|
|
}
|
|
|
|
fn view(&self) -> Html {
|
|
html! {
|
|
<div>
|
|
<div>
|
|
<textarea rows=5
|
|
value=&self.value
|
|
oninput=self.link.callback(|e: InputData| Msg::GotInput(e.value))
|
|
placeholder="placeholder">
|
|
</textarea>
|
|
<button onclick=self.link.callback(|_| Msg::Clicked)>{ "change value" }</button>
|
|
</div>
|
|
<div>
|
|
{&self.value}
|
|
</div>
|
|
</div>
|
|
}
|
|
}
|
|
}
|