basic.rs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. div {
  26. div {
  27. div {
  28. div {
  29. div {
  30. Fragment {
  31. a {"wo"}
  32. p {"wo"}
  33. li {"wo"}
  34. em {"wo"}
  35. }
  36. }
  37. }
  38. Child {}
  39. }
  40. Child {}
  41. }
  42. Child {}
  43. }
  44. ul {
  45. {(0..*count).map(|f| rsx!{
  46. li { "a - {f}" }
  47. li { "b - {f}" }
  48. li { "c - {f}" }
  49. })}
  50. }
  51. }
  52. })
  53. };
  54. static Child: FC<()> = |cx| {
  55. cx.render(rsx! {
  56. div {
  57. div {
  58. div {
  59. "hello child"
  60. }
  61. }
  62. }
  63. })
  64. };