1
0

basic.rs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. let mut content = use_state(cx, || String::new());
  23. cx.render(rsx! {
  24. div {
  25. input {
  26. value: "{content}"
  27. oninput: move |e| {
  28. content.set(e.value());
  29. }
  30. }
  31. button {
  32. onclick: move |_| count += 1,
  33. "Click to add."
  34. "Current count: {count}"
  35. }
  36. select {
  37. name: "cars"
  38. id: "cars"
  39. value: "h1"
  40. oninput: move |ev| {
  41. match ev.value().as_str() {
  42. "h1" => count.set(0),
  43. "h2" => count.set(5),
  44. "h3" => count.set(10),
  45. s => {}
  46. }
  47. },
  48. option { value: "h1", "h1" }
  49. option { value: "h2", "h2" }
  50. option { value: "h3", "h3" }
  51. }
  52. ul {
  53. {(0..*count).map(|f| rsx!{
  54. li { "a - {f}" }
  55. li { "b - {f}" }
  56. li { "c - {f}" }
  57. })}
  58. }
  59. {render_bullets(cx)}
  60. Child {}
  61. }
  62. })
  63. };
  64. fn render_bullets(cx: Context) -> DomTree {
  65. rsx!(cx, div {
  66. "bite me"
  67. })
  68. }
  69. static Child: FC<()> = |cx, props| rsx!(cx, div {"hello child"});