1
0

basic.rs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //! Basic example that renders a simple VNode to the browser.
  2. // all these imports are done automatically with the `dioxus` crate and `prelude`
  3. // need to do them manually for this example
  4. use dioxus::events::on::MouseEvent;
  5. use dioxus_core as dioxus;
  6. use dioxus_core::prelude::*;
  7. use dioxus_hooks::*;
  8. use dioxus_html as dioxus_elements;
  9. use dioxus::prelude::*;
  10. use dioxus_web::*;
  11. use std::future::Future;
  12. use std::{pin::Pin, time::Duration};
  13. fn main() {
  14. // Setup logging
  15. wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
  16. console_error_panic_hook::set_once();
  17. // Run the app
  18. dioxus_web::launch(APP, |c| c)
  19. }
  20. static APP: FC<()> = |cx, props| {
  21. let mut count = use_state(cx, || 3);
  22. cx.render(rsx! {
  23. button {
  24. // onclick: move |_| count += 1,
  25. onmouseover: move |_| count += 5,
  26. onmouseout: move |_| count -= 5,
  27. "Click to add."
  28. "Current count: {count}"
  29. }
  30. // div {
  31. // button {
  32. // onclick: move |_| count += 1,
  33. // "Click to add."
  34. // "Current count: {count}"
  35. // }
  36. // ul {
  37. // {(0..*count).map(|f| rsx!{
  38. // li { "a - {f}" }
  39. // li { "b - {f}" }
  40. // li { "c - {f}" }
  41. // })}
  42. // }
  43. // Child {}
  44. // }
  45. })
  46. };
  47. // static Child: FC<()> = |cx, props| {
  48. // cx.render(rsx! {
  49. // div {
  50. // div {
  51. // div {
  52. // "hello child"
  53. // }
  54. // }
  55. // }
  56. // })
  57. // };