Replies: 1 comment 1 reply
-
Yeah just to be clear your solution is not a hack, it's idiomatic Rust. Another, slightly different or better approach could be: let name_for_len = name.clone();
let is_error = {
let name = name.clone();
move || name.len() as i64 > count()
}; Depends on your preference for style. Similarly, let is_error = move || name.len() as i64 > count();
let not_error = {
let is_error = is_error.clone();
move || !is_error();
};
view! { cx,
<p class:not-error=not_error>"The name "{name}" is too long: "{is_error}</p>
} But we do also provide a #[component]
pub fn Test(cx: Scope, name: String) -> impl IntoView {
let (count, _set_count) = create_signal(cx, 0);
let is_error = Signal::derive(cx, move || name.len() as i64 > count());
let not_error = move || !is_error();
view! {
cx,
<p class:not-error=not_error>"The name "{name}" is too long: "{is_error}</p>
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The book describes how one creates dependent signals, for example something like this:
All well and good!
But what if one of the values used in the derived signal is not
Copy
?Something along what happens in the following (somewhat contrived) example has happened to me on multiple occasions:
The problem here seems to be that
name
is in fact notCopy
and hence my derived signals stop beingCopy
too. As a result myis_error
signal is moved into thenot_error
one, and no longer available for subsequent use.Is my approach conceptually wrong somehow?
I have had to do hacks like this, which don't scale well at all:
Any ideas and thoughts and feedback would be greatly appreciated!
🙏
Beta Was this translation helpful? Give feedback.
All reactions