Last active
December 14, 2018 05:28
-
-
Save infinite-Joy/2c5b6593e0642ecef9f21f48c0889e44 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[macro_use] | |
extern crate yew; | |
use yew::prelude::*; | |
struct Model { | |
hello: String, | |
} | |
enum Msg { | |
DoIt, | |
} | |
impl Component for Model { | |
// Some details omitted. Explore the examples to see more. | |
type Message = Msg; | |
type Properties = (); | |
fn create(_: Self::Properties, _: ComponentLink<Self>) -> Self { | |
Model { | |
hello: "".to_string(), | |
} | |
} | |
fn update(&mut self, msg: Self::Message) -> ShouldRender { | |
match msg { | |
Msg::DoIt => { | |
// Update your model on events | |
self.hello = "hello world".to_string(); | |
true | |
} | |
} | |
} | |
} | |
impl Renderable<Model> for Model { | |
fn view(&self) -> Html<Self> { | |
html! { | |
// Render your model here | |
<div> | |
<button onclick=|_| Msg::DoIt,>{ "Click me!" }</button> | |
</div> | |
<div> | |
<p>{&self.hello}</p> | |
</div> | |
} | |
} | |
} | |
fn main() { | |
yew::initialize(); | |
App::<Model>::new().mount_to_body(); | |
yew::run_loop(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment