DOCUMENTATION IN PROGRESS
Leptos Fetch
About
Leptos Fetch is a async state management library for Leptos.
The successor of, and heavily inspired by Leptos Query, which has been unmaintained for ~1 year.
Queries are useful for data fetching, caching, and synchronization with server state.
This crate provides:
- Caching
- Request de-duplication
- Invalidation
- Background refetching
Refetch intervals- Memory management with cache lifetimes
CancellationDebugging tools- Optimistic updates
Client side cache persistance (localstorage, indexdb, custom, etc.)
Lines that have a strike through are features not currently brought over from Leptos Query.
Feature Flags
ssrServer-side rendering: Initiate queries on the server.
Version compatibility for Leptos and Leptos Query
The table below shows the compatible versions of leptos-fetch for each leptos version. Ensure you are using compatible versions to avoid potential issues.
leptos version |
leptos-fetch version |
|---|---|
| 0.7.* | 0.1.* |
Installation
If using ssr, add the relevant feature to your Cargo.toml when in ssr:
[]
= [
"leptos-fetch/ssr",
# ...
]
Quick Start
In the root of your App, provide a query client with [provide_query_client] or [provide_query_client_with_options] if you want to override the default options.
use *;
use QueryClient;
Any async function can be used as a query:
/// Query fetcher.
async
Now you can use the query in any component in your app.
use *;
use QueryClient;
QueryScope and QueryScopeLocal can be used instead of directly passing a function, this allows setting options specific to a query type:
use Duration;
use ;
// this can be used just like the function directly in QueryClient methods.
/// Query fetcher.
async