basic.rs 1.1 KB

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