Skip to content

Lite Query

The lightweight, single-file data loading library for React.

Basic Usage

import { useQuery } from './utils/lite-query';
const { data, error, isLoading } = useQuery({
queryKey: 'posts',
queryFn: () => fetch('https://jsonplaceholder.typicode.com/posts').then(res => res.json())
});
if (isLoading) return 'Loading...';
if (error) return `Error: ${error.message}`;

How to Install

  1. Simply copy this file and put it anywhere in your project.

  2. If you’d like to install it as a package, you can use this command:

Terminal window
npx jsr add @orva/lite-query

Features

Lite Query address all the data fetching issues raised in the React Documentation caused by the useEffect hook such as:

Data Caching

Simple caching system preventing multiple requests for the same data.

Prefetching

Fetch data before it’s needed, or even before React renders the component.

SWR

Stale-While-Revalidate supported meaning you can show stale data while fetching new data in the background.

And much more...

Learn more about all the features in the Lite Query Docs.