You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
When I first tried to create a conditionally rendered input element, I ran into the issue of recreating the input element each time its value changes.
use leptos::*;#[component]pubfnInput() -> implIntoView{let(name, set_name) = create_signal(Some("Controlled".to_string()));view!{{move || {
name.get()
.map(|name| {
view! {
<input
type="text"
on:input=move |ev| {
set_name(Some(event_target_value(&ev)));
}// the `prop:` syntax lets you update a DOM property,// rather than an attribute.
prop:value=name
/>
}})}}}}
This is currently the right way to do it (from #2350):
However, it's inconvenient to have to call unwrap() because the Rust built-in match isn't used.
Describe the solution you'd like
There may be a better way of doing this but this makes it super convenient while working and following normal Rust control flow:
The is_some function you linked only creates a derived signal that calls is_some on an option. It can save a few characters of code, maybe 1 line of code in some situations.
Is your feature request related to a problem? Please describe.
When I first tried to create a conditionally rendered input element, I ran into the issue of recreating the input element each time its value changes.
This is currently the right way to do it (from #2350):
However, it's inconvenient to have to call
unwrap()
because the Rust built-inmatch
isn't used.Describe the solution you'd like
There may be a better way of doing this but this makes it super convenient while working and following normal Rust control flow:
I also made a impl function for reading and writing which is nice to use:
which can be used like this:
Describe alternatives you've considered
Using
<Show />
or doing something similar to what<Show />
does.Additional context
Based on #2350 (comment)
The text was updated successfully, but these errors were encountered: