DioxusLabs / example-projects

Featured Dioxus projects on how to build clean user interfaces in Rust
486 stars 64 forks source link

Hangman #40

Closed agreyyy closed 9 months ago

agreyyy commented 9 months ago

Simple Hangman game written in Dioxus. Demonstrates basic state management, memoization and interactivity in Dioxus desktop, could run on the web too, but I have no tested it.

agreyyy commented 9 months ago

A game example would be a great addition to the projects repo. Dioxus' isn't built specifically for games, but for simple games with a lot of UI it could be useful

There are a few places the code could be simplified and one small error that makes the code not run in the workspace.

You could also run Clippy to catch a few extra areas where the code could be simplified

All of this feedback is really good, especially the one about just using the stage variable in the Hangman component instead of a bool vector. I have one question about use_effect though. How can i use it in the same way i used use_memo in this repo, since im not making any async calls and use_effect requires that the callback implements IntoFuture? Do i just shove the same code inside an async move block, or is there a different hook for this specific usecase?

ealmloff commented 9 months ago

A game example would be a great addition to the projects repo. Dioxus' isn't built specifically for games, but for simple games with a lot of UI it could be useful There are a few places the code could be simplified and one small error that makes the code not run in the workspace. You could also run Clippy to catch a few extra areas where the code could be simplified

All of this feedback is really good, especially the one about just using the stage variable in the Hangman component instead of a bool vector. I have one question about use_effect though. How can i use it in the same way i used use_memo in this repo, since im not making any async calls and use_effect requires that the callback implements IntoFuture? Do i just shove the same code inside an async move block, or is there a different hook for this specific usecase?

You can just put the code before the async block:

let effect = use_effect(cx, (), |_| {
    // your code here
    async {}
});