controlled_inputs.rs 980 B

12345678910111213141516171819202122232425262728293031323334353637
  1. use dioxus::prelude::*;
  2. fn main() {}
  3. pub static Example: Component = |cx| {
  4. cx.render(rsx! {
  5. div {
  6. }
  7. })
  8. };
  9. // A controlled component:
  10. static ControlledSelect: Component = |cx| {
  11. let value = use_state(&cx, || String::from("Grapefruit"));
  12. cx.render(rsx! {
  13. select { value: "{value}", onchange: move |evt| value.set(evt.value()),
  14. option { value: "Grapefruit", "Grapefruit"}
  15. option { value: "Lime", "Lime"}
  16. option { value: "Coconut", "Coconut"}
  17. option { value: "Mango", "Mango"}
  18. }
  19. })
  20. };
  21. // TODO - how do uncontrolled things work?
  22. static UncontrolledSelect: Component = |cx| {
  23. let value = use_state(&cx, || String::new());
  24. cx.render(rsx! {
  25. select {
  26. option { value: "Grapefruit", "Grapefruit"}
  27. option { value: "Lime", "Lime"}
  28. option { value: "Coconut", "Coconut"}
  29. option { value: "Mango", "Mango"}
  30. }
  31. })
  32. };