2021-07-11 18:49:52 +00:00
|
|
|
//! Basic example that renders a simple VNode to the browser.
|
|
|
|
|
|
|
|
use dioxus::events::on::MouseEvent;
|
|
|
|
use dioxus_core as dioxus;
|
|
|
|
use dioxus_core::prelude::*;
|
2021-09-25 01:46:23 +00:00
|
|
|
use dioxus_core_macro::*;
|
2021-07-11 18:49:52 +00:00
|
|
|
use dioxus_hooks::*;
|
|
|
|
use dioxus_html as dioxus_elements;
|
|
|
|
|
|
|
|
use std::future::Future;
|
|
|
|
|
|
|
|
use std::{pin::Pin, time::Duration};
|
|
|
|
|
|
|
|
use dioxus::prelude::*;
|
|
|
|
|
|
|
|
use dioxus_web::*;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// Setup logging
|
|
|
|
wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
|
|
|
|
console_error_panic_hook::set_once();
|
|
|
|
|
|
|
|
// Run the app
|
2021-07-18 16:39:32 +00:00
|
|
|
dioxus_web::launch(App, |c| c)
|
2021-07-11 18:49:52 +00:00
|
|
|
}
|
|
|
|
|
2021-10-16 21:37:28 +00:00
|
|
|
static App: FC<()> = |(cx, props)| {
|
2021-07-11 18:49:52 +00:00
|
|
|
let mut state = use_state(cx, || 0);
|
|
|
|
cx.render(rsx! {
|
|
|
|
div {
|
2021-07-15 03:18:02 +00:00
|
|
|
style: {
|
|
|
|
align_items: "center"
|
|
|
|
}
|
2021-07-11 18:49:52 +00:00
|
|
|
section { class: "py-12 px-4 text-center"
|
|
|
|
div { class: "w-full max-w-2xl mx-auto"
|
|
|
|
span { class: "text-sm font-semibold"
|
|
|
|
"static subtree"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
section { class: "py-12 px-4 text-center"
|
|
|
|
div { class: "w-full max-w-2xl mx-auto"
|
|
|
|
span { class: "text-sm font-semibold"
|
|
|
|
"dynamic subtree {state}"
|
|
|
|
}
|
|
|
|
div {
|
2021-10-04 05:28:04 +00:00
|
|
|
button { onclick: move |e| state+=1, "incr" }
|
2021-07-11 18:49:52 +00:00
|
|
|
br {}
|
2021-10-04 05:28:04 +00:00
|
|
|
button { onclick: move |e| state-=1, "decr" }
|
2021-07-11 18:49:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
};
|