2020-03-29 19:56:55 +02:00
|
|
|
use yew::{html, Callback, ClickEvent, Component, ComponentLink, Html, ShouldRender};
|
2020-03-27 12:17:27 +01:00
|
|
|
|
2020-03-29 19:56:55 +02:00
|
|
|
struct App {
|
|
|
|
clicked: bool,
|
|
|
|
onclick: Callback<ClickEvent>,
|
|
|
|
}
|
|
|
|
|
|
|
|
enum Msg {
|
|
|
|
Click,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Component for App {
|
|
|
|
type Message = Msg;
|
|
|
|
type Properties = ();
|
|
|
|
|
|
|
|
fn create(_: Self::Properties, link: ComponentLink<Self>) -> Self {
|
|
|
|
App {
|
|
|
|
clicked: false,
|
|
|
|
onclick: link.callback(|_| Msg::Click),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn update(&mut self, msg: Self::Message) -> ShouldRender {
|
|
|
|
match msg {
|
|
|
|
Msg::Click => {
|
|
|
|
self.clicked = true;
|
|
|
|
true // Indicate that the Component should re-render
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn view(&self) -> Html {
|
|
|
|
let button_text = if self.clicked {
|
|
|
|
"Clicked!"
|
|
|
|
} else {
|
|
|
|
"Click me!"
|
|
|
|
};
|
|
|
|
|
|
|
|
html! {
|
|
|
|
<button onclick=&self.onclick>{ button_text }</button>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
yew::start_app::<App>();
|
|
|
|
}
|