basic.rs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. div {
  24. button {
  25. onclick: move |_| count += 1,
  26. "Click to add."
  27. "Current count: {count}"
  28. }
  29. ul {
  30. {(0..*count).map(|f| rsx!{
  31. li { "a - {f}" }
  32. li { "b - {f}" }
  33. li { "c - {f}" }
  34. })}
  35. }
  36. Child {}
  37. }
  38. })
  39. };
  40. static Child: FC<()> = |cx, props|{
  41. cx.render(rsx! {
  42. div {
  43. div {
  44. div {
  45. "hello child"
  46. }
  47. }
  48. }
  49. })
  50. };