I'm trying to store a variable in state and have it always updated alongside an input field. It looks something like this:
#[function_component]
fn component() -> Html {
let n = use_state(|_| 5.into());
html! {
<input type="number" value={n}></input>
}
}
I get this error:
error[E0277]: the trait bound `UseStateHandle<_>: IntoPropValue<Option<implicit_clone::unsync::IString>>` is not satisfied
--> src/main.rs:21:24
|
21 | value={n}
| ^ the trait `IntoPropValue<Option<implicit_clone::unsync::IString>>` is not implemented for `UseStateHandle<_>`
|
I read this as "you can't use state as an attribute" but certainly I'm just doing something wrong. I also don't see any method available on the UseStateHandle struct that will read/convert the value as needed. Why does an attribute value need to come from props? This component needs to keep track of some global state that will perform some different arithmetic based on n. What am I missing here?