Crates.io | dioxus-query |
lib.rs | dioxus-query |
version | |
source | src |
created_at | 2023-08-05 20:26:40.674356+00 |
updated_at | 2025-04-05 11:52:04.984966+00 |
description | Fully-typed, async, reusable cached state management for Dioxus 🧬 |
homepage | https://github.com/marc2332/dioxus-query |
repository | https://github.com/marc2332/dioxus-query |
max_upload_size | |
id | 936774 |
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 |
Fully-typed, async, reusable cached state management for Dioxus 🧬. Inspired by TanStack Query
.
See the Docs or join the Discord.
Install the latest release:
cargo add dioxus-query
cargo run --example simple
#[derive(Clone, PartialEq, Eq, Hash)]
enum QueryKey {
User(usize),
}
#[derive(Debug)]
enum QueryError {
UserNotFound(usize),
Unknown
}
#[derive(PartialEq, Debug)]
enum QueryValue {
UserName(String),
}
async fn fetch_user(keys: Vec<QueryKey>) -> QueryResult<QueryValue, QueryError> {
if let Some(QueryKey::User(id)) = keys.first() {
println!("Fetching user {id}");
sleep(Duration::from_millis(1000)).await;
match id {
0 => Ok(QueryValue::UserName("Marc".to_string())),
_ => Err(QueryError::UserNotFound(*id)),
}
} else {
Err(QueryError::Unknown)
}
}
#[allow(non_snake_case)]
#[component]
fn User(id: usize) -> Element {
let value = use_get_query([QueryKey::User(id)], fetch_user);
rsx!( p { "{value.result().value():?}" } )
}
fn app() -> Element {
let client = use_init_query_client::<QueryValue, QueryError, QueryKey>();
let onclick = move |_| {
client.invalidate_queries(&[QueryKey::User(0)]);
};
rsx!(
User { id: 0 }
button { onclick, label { "Refresh" } }
)
}
Renderer-agnostic
Queries and mutations
Typed Mutations, Query keys, Errors and Values
Invalidate queries manually
Invalidate queries when keys change
Concurrent and batching of queries
Concurrent mutations
Background interval invalidation
On window focus invalidation
MIT License