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...
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

Resize observer hooks for Dioxus 🧬

dioxus-resize-observer Resize observer hooks for Dioxus 🧬. Support 0.1.0 - Dioxus v0.4 🧬 git - Dioxus v0.5 Web renderer (WASM) Example use dioxus::p

Fermyon Spin + Dioxus - Client Side Rendering (CSR) template with TailwindCSS
Fermyon Spin + Dioxus - Client Side Rendering (CSR) template with TailwindCSS

spin-dioxus-csr Fermyon Spin + Dioxus - Client Side Rendering (CSR) template with Tailwind Setup Accomodate "chicken & egg" issue for https://github.c

A statically typed language that can deeply improve the Python ecosystem

The Erg Programming Language This is the main source code repository for Erg. This contains the compiler and documentation. 日本語 | 简体中文 | 繁體中文 Erg can

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
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 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
(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
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

Jon Kelley 13 Dec 19, 2022
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

Muideen 3 Mar 30, 2024
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

Zihua Wu 8 Dec 28, 2022