1
0

basic.rs 1.9 KB

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