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

PartialOrd for UseState #1473

Merged
merged 1 commit into from
Sep 19, 2023
Merged

PartialOrd for UseState #1473

merged 1 commit into from
Sep 19, 2023

Conversation

Calastrophe
Copy link
Contributor

I have implemented PartialOrd for UseState to allow for some better readability. It may be a small change, but I found .get() quite annoying. It just makes more sense to have PartialOrd implemented.

Essentially instead of,

use dioxus::prelude::*;

fn main() {
    dioxus_desktop::launch(app);
}

fn app(cx: Scope) -> Element {
    let mut count = use_state(cx, || 0);
    let other_count = use_state(cx, || 10);

    cx.render(rsx! (
        h1 { "Counter: {count}" }
        button { onclick: move |_| if count.get() < other_count.get() { count += 1 }, "Tick up"}
        button { onclick: move |_| if *count.get() > 0 { count -= 1}, "Tick down"}
    ))
}

now we have,

use dioxus::prelude::*;

fn main() {
    dioxus_desktop::launch(app);
}

fn app(cx: Scope) -> Element {
    let mut count = use_state(cx, || 0);
    let other_count = use_state(cx, || 10);

    cx.render(rsx! (
        h1 { "Counter: {count}" }
        button { onclick: move |_| if count < other_count { count += 1 }, "Tick up"}
        button { onclick: move |_| if *count > 0 { count -= 1}, "Tick down"}
    ))
}

Please let me know if anything needs to be changed to meet the requirements for the merge, i.e. testing, etc.

Copy link
Member

@ealmloff ealmloff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

(formatting issue is unrelated)

@ealmloff ealmloff merged commit 98babe1 into DioxusLabs:master Sep 19, 2023
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants