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
Hi,
I am studying the book, and in Chapter 3.3, the code after "if you are savvy..." leads to this:
#[component]
fn ProgressBar(
#[prop(default = 100)] max: u16,
progress: impl Fn() -> i32 + Send + Sync + 'static,
) -> impl IntoView {
view! {
<progress
max=max
value=progress
/>
// Add a line-break to avoid overlap
<br/>
}
}
#[component]
fn App() -> impl IntoView {
let (count, set_count) = signal(0);
// Defining the closure that accesses the signal
let double_count = move || count.get() * 2;
view! {
<button
on:click=move |_| {
set_count.update(|n| *n +=1 );
}
>
"Click me"
</button>
// Progress Bar with Signal
<ProgressBar progress = count> // <--- Fails here
<ProgressBar progress = double_count/>
}
}
Trunk serve fails to compile because "expected an Fn() closure, found leptos::prelude::ReadSignal<{integer}>"
To make sure that I was not mistaken, I just copied and pasted the code for the progress bar (the upper component in the listing above)
Most propably I had done something wrong, but maybe, there is a glitch in this chapter. Could you please have a look?
Edit: I formerly pasted a piece of Code, where I bound the type impl FnOnce() -> i32 to the variable double count. This was a attempt to troubleshoot this issue. Sorry for that.
Thanks
Simon
The text was updated successfully, but these errors were encountered:
This only works on nightly, where signals directly implement the Fn() traits. The book was later rewritten to default to stable-only features. This probably just needs to be reworded now to clarify that this only works on nightly.
Hi,
I am studying the book, and in Chapter 3.3, the code after "if you are savvy..." leads to this:
Trunk serve fails to compile because "expected an Fn() closure, found
leptos::prelude::ReadSignal<{integer}>
"To make sure that I was not mistaken, I just copied and pasted the code for the progress bar (the upper component in the listing above)
Most propably I had done something wrong, but maybe, there is a glitch in this chapter. Could you please have a look?
Edit: I formerly pasted a piece of Code, where I bound the type
impl FnOnce() -> i32
to the variabledouble count
. This was a attempt to troubleshoot this issue. Sorry for that.Thanks
Simon
The text was updated successfully, but these errors were encountered: