btns.rs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //! Example: Webview Renderer
  2. //! -------------------------
  3. //!
  4. //! This example shows how to use the dioxus_desktop crate to build a basic desktop application.
  5. //!
  6. //! Under the hood, the dioxus_desktop crate bridges a native Dioxus VirtualDom with a custom prebuit application running
  7. //! in the webview runtime. Custom handlers are provided for the webview instance to consume patches and emit user events
  8. //! into the native VDom instance.
  9. //!
  10. //! Currently, NodeRefs won't work properly, but all other event functionality will.
  11. use dioxus::prelude::*;
  12. use dioxus_core as dioxus;
  13. use dioxus_core_macro::*;
  14. use dioxus_hooks::*;
  15. use dioxus_html as dioxus_elements;
  16. // #[cfg]
  17. fn main() {
  18. wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
  19. dioxus_web::launch(App, |c| c);
  20. // env_logger::init();
  21. // dioxus::web::launch(App, |c| c);
  22. }
  23. static App: FC<()> = |cx, props| {
  24. dbg!("rednering parent");
  25. cx.render(rsx! {
  26. div {
  27. But {
  28. h1 {"he"}
  29. }
  30. // But {
  31. // h1 {"llo"}
  32. // }
  33. // But {
  34. // h1 {"world"}
  35. // }
  36. }
  37. })
  38. };
  39. static But: FC<()> = |cx, props| {
  40. let mut count = use_state(cx, || 0);
  41. // let d = Dropper { name: "asd" };
  42. // let handler = move |_| {
  43. // dbg!(d.name);
  44. // };
  45. cx.render(rsx! {
  46. div {
  47. h1 { "Hifive counter: {count}" }
  48. {cx.children()}
  49. button { onclick: move |_| count += 1, "Up high!" }
  50. button { onclick: move |_| count -= 1, "Down low!" }
  51. // button { onclick: {handler}, "Down low!" }
  52. }
  53. })
  54. };
  55. // struct Dropper {
  56. // name: &'static str,
  57. // }
  58. // impl Drop for Dropper {
  59. // fn drop(&mut self) {
  60. // dbg!("dropped");
  61. // }
  62. // }