input_controlled.rs 482 B

123456789101112131415161718192021
  1. #![allow(non_snake_case)]
  2. use dioxus::prelude::*;
  3. fn main() {
  4. dioxus::desktop::launch(App);
  5. }
  6. // ANCHOR: component
  7. fn App(cx: Scope) -> Element {
  8. let name = use_state(&cx, || "bob".to_string());
  9. cx.render(rsx! {
  10. input {
  11. // we tell the component what to render
  12. value: "{name}",
  13. // and what to do when the value changes
  14. oninput: move |evt| name.set(evt.value.clone()),
  15. }
  16. })
  17. }
  18. // ANCHOR_END: component