https://github.com/marc2332/dioxus-query
Fully-typed, async, reusable state management and synchronization for Dioxus 🧬
https://github.com/marc2332/dioxus-query
async dioxus hacktoberfest rust state-management
Last synced: about 1 year ago
JSON representation
Fully-typed, async, reusable state management and synchronization for Dioxus 🧬
- Host: GitHub
- URL: https://github.com/marc2332/dioxus-query
- Owner: marc2332
- License: mit
- Created: 2023-08-05T20:23:23.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2025-04-05T12:22:12.000Z (about 1 year ago)
- Last Synced: 2025-04-13T20:12:11.647Z (about 1 year ago)
- Topics: async, dioxus, hacktoberfest, rust, state-management
- Language: Rust
- Homepage:
- Size: 109 KB
- Stars: 74
- Watchers: 2
- Forks: 3
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
[](https://discord.gg/gwuU8vGRPr)
# dioxus-query 🦀⚡
**Fully-typed, async, reusable cached state management** for [Dioxus 🧬](https://dioxuslabs.com/). Inspired by [`TanStack Query`](https://tanstack.com/query/latest/docs/react/overview).
See the [Docs](https://docs.rs/dioxus-query/latest/dioxus_query/) or join the [Discord](https://discord.gg/gwuU8vGRPr).
## Support
- **Dioxus v0.6** 🧬
- All renderers ([web](https://dioxuslabs.com/learn/0.4/getting_started/wasm), [desktop](https://dioxuslabs.com/learn/0.4/getting_started/desktop), [freya](https://github.com/marc2332/freya), etc)
- Both WASM and native targets
## Installation
Install the latest release:
```bash
cargo add dioxus-query
```
## Example
```bash
cargo run --example simple
```
## Usage
```rust
#[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) -> QueryResult {
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::();
let onclick = move |_| {
client.invalidate_queries(&[QueryKey::User(0)]);
};
rsx!(
User { id: 0 }
button { onclick, label { "Refresh" } }
)
}
```
## Features
- [x] Renderer-agnostic
- [x] Queries and mutations
- [x] Typed Mutations, Query keys, Errors and Values
- [x] Invalidate queries manually
- [x] Invalidate queries when keys change
- [x] Concurrent and batching of queries
- [x] Concurrent mutations
- [ ] Background interval invalidation
- [ ] On window focus invalidation
## To Do
- Tests
- Documentation
- Real-world examples
MIT License