basic.rs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //! Basic example that renders a simple VNode to the browser.
  2. use dioxus_core as dioxus;
  3. use dioxus_core::prelude::*;
  4. use dioxus_web::*;
  5. fn main() {
  6. // Setup logging
  7. wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
  8. console_error_panic_hook::set_once();
  9. // Run the app
  10. wasm_bindgen_futures::spawn_local(WebsysRenderer::start(App));
  11. }
  12. static App: FC<()> = |cx| {
  13. cx.render(rsx! {
  14. div {
  15. h1 {"hello"}
  16. C1 {}
  17. C2 {}
  18. }
  19. })
  20. };
  21. static C1: FC<()> = |cx| {
  22. cx.render(rsx! {
  23. button {
  24. "numba 1"
  25. }
  26. })
  27. };
  28. static C2: FC<()> = |cx| {
  29. cx.render(rsx! {
  30. button {
  31. "numba 2"
  32. }
  33. })
  34. };
  35. static DocExamples: FC<()> = |cx| {
  36. //
  37. let is_ready = false;
  38. let items = (0..10).map(|i| rsx! { li {"{i}"} });
  39. let _ = rsx! {
  40. ul {
  41. {items}
  42. }
  43. };
  44. // rsx! {
  45. // div {}
  46. // h1 {}
  47. // {""}
  48. // "asbasd"
  49. // dioxus::Fragment {
  50. // //
  51. // }
  52. // }
  53. cx.render(rsx! {
  54. div {
  55. { is_ready.then(|| rsx!{ h1 {"We are ready!"} }) }
  56. }
  57. })
  58. };