use leptos::ev::SubmitEvent; use leptos::prelude::*; #[component] fn App() -> impl IntoView { view! {
"Name is: " {name}
} } #[component] fn UncontrolledComponent() -> impl IntoView { // import the type for use leptos::html::Input; let (name, set_name) = signal("Uncontrolled".to_string()); // we'll use a NodeRef to store a reference to the input element // this will be filled when the element is created let input_element: NodeRef = NodeRef::new(); // fires when the form `submit` event happens // this will store the value of the in our signal let on_submit = move |ev: SubmitEvent| { // stop the page from reloading! ev.prevent_default(); // here, we'll extract the value from the input let value = input_element .get() // event handlers can only fire after the view // is mounted to the DOM, so the `NodeRef` will be `Some` .expect(" to exist") // `NodeRef` implements `Deref` for the DOM element type // this means we can call`HtmlInputElement::value()` // to get the current value of the input .value(); set_name.set(value); }; view! {"Name is: " {name}
} } // This `main` function is the entry point into the app // It just mounts our component to the // Because we defined it as `fn App`, we can now use it in a // template as