-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path\
44 lines (36 loc) · 839 Bytes
/
\
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use yew::prelude::*;
use gloo_net::websocket;
use gloo_console::log;
use wasm_bindgen_futures::spawn_local;
enum Msg {
AddOne,
}
struct App {
value: i64,
}
impl Component for App {
type Message = Msg;
type Properties = ();
fn create(_ctx: &Context<Self>) -> Self {
Self { value: 0 }
}
fn update(&mut self, _ctx: &Context<Self>, msg: Self::Message) -> bool {
match msg {
Msg::AddOne => {
self.value += 1;
true
}
}
}
fn view(&self, ctx: &Context<Self>) -> Html {
html! {
<div>
<button onclick={ctx.link().callback(|_| Msg::AddOne)}>{ "+1" }</button>
<p>{ self.value }</p>
</div>
}
}
}
fn main() {
yew::Renderer::<App>::new().render();
}