Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in Sample Code in chapter "A Basic Component" #54

Open
liangcorp opened this issue Jan 29, 2024 · 2 comments
Open

Bug in Sample Code in chapter "A Basic Component" #54

liangcorp opened this issue Jan 29, 2024 · 2 comments
Labels
nightly Things that need to be changed to use the stable syntax by default.

Comments

@liangcorp
Copy link

There is a bug in the first sample code in chapter "A Basic Component". set_count(3) should be set_count.set(3).

#[component]
fn App() -> impl IntoView {
    let (count, set_count) = create_signal(0);

    view! {
        <button
            on:click=move |_| {
                set_count(3);
            }
        >
            "Click me: "


            {move || count.get()}
        </button>
    }
}

Screenshot from 2024-01-29 01-17-57

@gbj
Copy link
Contributor

gbj commented Jan 29, 2024

Thanks for your message, and apologies for the confusion!

The README in the repo notes that most of the examples default to the nightly feature on Leptos, which enables this syntax. The "Getting Started" mentions this distinction too, but could maybe be clearer about the fact that the book is using the nightly syntax and if you're using stable, then the function-call syntax for signals shouldn't work.

We've discussed migrating the book to use the stable syntax by default in the future. I'm generally hesitant to do that because I find the mental-model advantages of the nightly syntax really useful:

// nightly: any signal access is a function call
let (count, set_count) = create_signal(1);
let double_count = move || count() * 2;
assert_eq!(count(), 1);
assert_eq!(double_count(), 1);

// stable: I have to remember whether something is a signal or derived, and update the syntax if that changes
let (count, set_count) = create_signal(1);
let double_count = move || count.get() * 2;

// works
assert_eq!(double_count(), 1);
// compile error
assert_eq!(count(), 1);

@liangcorp
Copy link
Author

Understandable. I would suggest to use stable as documentation base after leptos reaches 1.0.

@gbj gbj closed this as completed Feb 4, 2024
@gbj gbj added the nightly Things that need to be changed to use the stable syntax by default. label Feb 16, 2024
@gbj gbj reopened this Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
nightly Things that need to be changed to use the stable syntax by default.
Projects
None yet
Development

No branches or pull requests

2 participants