Testing out yew
Signed-off-by: Marko Korhonen <marko.korhonen@reekynet.com>
This commit is contained in:
parent
75b2ae330a
commit
be88bb19fc
5 changed files with 634 additions and 0 deletions
40
project/src/app/mod.rs
Normal file
40
project/src/app/mod.rs
Normal file
|
@ -0,0 +1,40 @@
|
|||
use yew::{html, Callback, ClickEvent, Component, ComponentLink, Html, ShouldRender};
|
||||
|
||||
pub struct App {
|
||||
clicked: bool,
|
||||
on_click: Callback<ClickEvent>,
|
||||
}
|
||||
|
||||
pub enum Msg {
|
||||
Click,
|
||||
}
|
||||
|
||||
impl Component for App {
|
||||
type Message = Msg;
|
||||
type Properties = ();
|
||||
|
||||
fn create(_: Self::Properties, link: ComponentLink<Self>) -> Self {
|
||||
App {
|
||||
clicked: false,
|
||||
on_click: 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.on_click>{ button_text }</button>
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue