basic.rs 1.2 KB

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