Data Caching
Simple caching system preventing multiple requests for the same data.
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}`;
Simply copy this file and put it anywhere in your project.
If you’d like to install it as a package, you can use this command:
npx jsr add @orva/lite-query
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.