Crates.io | dioxus-hooks |
lib.rs | dioxus-hooks |
version | |
source | src |
created_at | 2022-01-03 07:22:02.664992 |
updated_at | 2024-12-07 03:38:29.215089 |
description | Basic useful hooks for Dioxus. |
homepage | https://dioxuslabs.com |
repository | https://github.com/DioxusLabs/dioxus/ |
max_upload_size | |
id | 506897 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Website | Guides | API Docs | Chat
dioxus-hooks
includes some basic useful hooks for Dioxus such as:
Unlike React, none of these hooks are foundational since they all build off the primitive use_hook
. You can extend these hooks with custom hooks in your own code. If you think they would be useful for the broader community, you can open a PR to add your hook to the Dioxus Awesome list.
If you aren't sure what hook to use, you can use this cheat sheet to help you decide:
Depending on where you need to access the state, you can put your state in one of three places:
Location | Where can you access the state? | Recommended for Libraries? | Examples |
---|---|---|---|
Hooks | Any components you pass it to | ✅ | use_signal(|| 0) , use_memo(|| state() * 2) |
Context | Any child components | ✅ | use_context_provider(|| Signal::new(0)) , use_context::<Signal<i32>>() |
Global | Anything in your app | ❌ | Signal::global(|| 0) |
If you don't have an initial value for your state, you can derive your state from other states with a closure or asynchronous function:
Hook | Reactive (reruns when dependencies change) | Async | Memorizes Output | Example |
---|---|---|---|---|
use_memo |
✅ | ❌ | ✅ | use_memo(move || count() * 2) |
use_resource |
✅ | ✅ | ❌ | use_resource(move || reqwest::get(format!("/users/{user_id}"))) |
use_future |
❌ | ✅ | ❌ | use_future(move || println!("{:?}", reqwest::get(format!("/users/{user_id}")))) |
The core hooks library doesn't provide hooks for persistent state, but you can extend the core hooks with hooks from dioxus-sdk and the dioxus-router to provide persistent state management.
State | Sharable | Example |
---|---|---|
use_persistent |
❌ | use_persistent("unique_key", move || initial_state) |
Router<Route> {} |
✅ | #[derive(Routable, Clone, PartialEq)] enum Route { #[route("/user/:id")] Homepage { id: u32 } } |
This project is licensed under the MIT license.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Dioxus by you shall be licensed as MIT without any additional terms or conditions.