basic.rs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. //! Basic example that renders a simple domtree to the browser.
  2. use dioxus_core::prelude::*;
  3. use dioxus_web::*;
  4. fn main() {
  5. // Setup logging
  6. wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
  7. console_error_panic_hook::set_once();
  8. // Run the app
  9. wasm_bindgen_futures::spawn_local(WebsysRenderer::start(App));
  10. }
  11. static App: FC<()> = |ctx, _| {
  12. log::info!("Ran component");
  13. use dioxus::builder::*;
  14. ctx.view(|b| {
  15. div(b)
  16. .child(text("hello"))
  17. .listeners([on(b, "click", |_| {
  18. //
  19. log::info!("button1 clicked!");
  20. })])
  21. .finish()
  22. })
  23. // ctx.view(html! {
  24. // <div onclick={move |_| log::info!("button1 clicked!")}>
  25. // "Hello"
  26. // // <div class="flex items-center justify-center flex-col">
  27. // // <div class="font-bold text-xl"> "Count is ..." </div>
  28. // // <button onclick={move |_| log::info!("button1 clicked!")}> "increment" </button>
  29. // // <button onclick={move |_| log::info!("button2 clicked!")}> "decrement" </button>
  30. // // </div>
  31. // </div>
  32. // })
  33. };