Fully-typed, async, reusable state management and synchronization for Dioxus 🧬

Overview

dioxus-query 🦀

Fully-typed, async, reusable state management and synchronization for Dioxus 🧬. Inspired by TanStack Query.

⚠️ Work in progress ⚠️

Installation

Compatible with Dioxus v0.4.

cargo add dioxus-query

Example

cargo run --example basic

Usage

#[derive(Clone, PartialEq, Debug)]
enum QueryKeys {
    User(usize),
}

#[derive(Clone, PartialEq, Debug)]
enum QueryError {
    UserNotFound(usize)
}

async fn fetch_user(id: usize) -> QueryResult<String, QueryError> {
    sleep(Duration::from_millis(1000)).await;
    match id {
        0 => Ok("Marc".to_string()),
        _ => Err(QueryError::UserNotFound(id)),
    }
    .into()
}

#[allow(non_snake_case)]
#[inline_props]
fn User(cx: Scope, id: usize) -> Element {
    to_owned![id];

    let value = use_query(cx, move || vec![QueryKeys::User(id)], {
        move |_keys| fetch_user(id)
    });

    render!( p { "{value.result():?}" } )
}

fn app(cx: Scope) -> Element {
    let client = use_provide_client(cx);

    let refresh = |_| client.invalidate_query(QueryKeys::User(0));

    render!(
        User { id: 0 }
        button { onclick: refresh, label { "Refresh" } }
    )
}

Features

  • Renderer-agnostic
  • Typed Query keys
  • Manual query invalidation
  • Automatic/smart query invalidation
  • Query aborting
  • Global Query caching

MIT License

You might also like...
Open source email client written in Rust and Dioxus. Under 🏗️
Open source email client written in Rust and Dioxus. Under 🏗️

Blazemail A full-featued, beautiful, mail client that doesn't suck. Works on mac, windows, linux, mobile, web, etc. Features, status Blazemail is curr

A cross-platofrm desktop app to manage your ports made with Dioxus and Rust.
A cross-platofrm desktop app to manage your ports made with Dioxus and Rust.

Port Manager A cross-platofrm desktop app to manage your ports made with Dioxus and Rust. This app has been tested only on macOS. Test on other platfo

Deploy dioxus-web to Vercel.

Dioxus demo This demo shows how to use Dioxus to build a static web application and deploy it to Vercel. Local development To run the demo locally, yo

Make data-driven table rendering easy with Dioxus

Dioxus Table Make data-driven table rendering easy with Dioxus Installation Until the next release of Dioxus this requires Dioxus nightly from git. Th

An html macro for dioxus applications.

dioxus html macro This crate offers an html! like macro for dioxus applications. It expands to the equivalent rsx! macro call you would have made othe

A library to provide abstractions to access common utilities when developing Dioxus applications.

🧰 Dioxus Standard Library 🚀 A platform agnostic library for supercharging your productivity with Dioxus. dioxus-std is a Dioxus standard library tha

A gui tool written in Dioxus to make it easy to release a workspace of crates to crates.io
A gui tool written in Dioxus to make it easy to release a workspace of crates to crates.io

Easy-Release: a visual tool for releasing workspaces of libraries A work-in-progress GUI for releasing a large workspace of crates manually, but easil

🧬 Material Icons for Dioxus

🧬 Dioxus Material Icons This project provides a simple but configurable component to render Google's Material Icons in Dioxus. 🚀 How to get started

🦀🔨 DevBcn Workshop - Full Stack Rust - Actix - Postgres - Shuttle - Dioxus
🦀🔨 DevBcn Workshop - Full Stack Rust - Actix - Postgres - Shuttle - Dioxus

Building a Movie Collection Manager - Full Stack Workshop with Rust, Actix, SQLx, Dioxus, and Shuttle Welcome to the this workshop! In this hands-on w

Comments
  • feat: Global caching

    feat: Global caching

    Changes

    • Run a global sequencial queries runner instead of multiple parallel queries runners
    • Cached queries results between callers of use_query
    • Typed QueryResults
    enhancement 
    opened by marc2332 0
Owner
Marc Espín
Probably coding while you read this
Marc Espín
global state management for dioxus built on the concept of atoms. currently under 🏗

Fermi: A global state management solution for Dioxus, inspired by Recoil.Js Fermi provides primitives for managing global state in Dioxus applications

Dioxus 15 Feb 12, 2022
Rustato: A powerful, thread-safe global state management library for Rust applications, offering type-safe, reactive state handling with an easy-to-use macro-based API.

Rustato State Manager A generical thread-safe global state manager for Rust Introduction • Features • Installation • Usage • Advanced Usage • Api Refe

BiteCraft 8 Sep 16, 2024
Execute Javascript code in the Dioxus, and get the return value ( for Dioxus )

Golde Dioxus Execute Javascript code in the Dioxus, and get the return value. This demo can help use Javascript to calc the + operator formula. use di

YuKun Liu 15 Dec 27, 2022
A template for starting a dioxus project to be used with dioxus-cli

A template for starting a dioxus project to be used with dioxus-cli

Dioxus 6 Nov 25, 2022
A Rust on-site channel benchmarking helper. Inter-Process (async / busy) & Intra-Process (async single threaded / async multi threaded)

On-Site Rust Channel Benchmarking Helper Deploy on server to determine which public crates are the fastest for communicating in different architecture

null 23 Jul 9, 2024
A parser combinator that is fully statically dispatched and supports both sync/async.

XParse A parser combinator that is fully statically dispatched and supports both sync & async parsing. How to use An example of a very simple JSON par

Alsein 4 Nov 27, 2023
Leptos Query - a robust asynchronous state management library for Leptos,

Leptos Query is a robust asynchronous state management library for Leptos, providing simplified data fetching, integrated reactivity, server-side rendering support, and intelligent cache management.

Nico Burniske 5 Jul 24, 2023
This is a `Rust` based package to help with the management of complex medicine (pill) management cycles.

reepicheep This is a Rust based package to help with the management of complex medicine (pill) management cycles. reepicheep notifies a person(s) via

Daniel B 24 Dec 13, 2023
Rust File Management CLI is a command-line tool written in Rust that provides essential file management functionalities. Whether you're working with files or directories, this tool simplifies common file operations with ease.

Rust FileOps Rust File Management CLI is a command-line tool written in Rust that provides essential file management functionalities. Whether you're w

Harikesh Ranjan Sinha 5 May 2, 2024
(Pre-Release Software) Secure, Encrypted, P2P chat written atop Warp, IPFS, LibP2P, Dioxus and many more awesome projects and protocols.

Uplink Privacy First, Modular, P2P messaging client built atop Warp. Uplink is written in pure Rust with a UI in Dioxus (which is also written in Rust

Satellite 13 Jan 25, 2023