Registry / testing / use-query

use-query

JSON →
library1.0.2jsnpmunverified

A lightweight React hook that wraps async data fetching with a useState-like interface. Version 1.0.2 provides a simple API returning loading, data, and error states. No built-in caching or deduplication; intended for simple per-component data fetching where minimal overhead is needed. Ships TypeScript definitions.

npm install use-query
INSTALL
IMPORT
SIG · USE-QUERY
U
use-query
testingjavascriptv1.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

useQuery
import useQuery from 'use-query'
Default export; ESM only.
useQuery
const useQuery = require('use-query').default
const useQuery = require('use-query')
CJS requires .default import
useQuery
import useQuery from 'use-query'
import { useQuery } from 'use-query'
Named export does not exist; must use default import

Shows basic usage of useQuery hook with loading, data, and error states.

import useQuery from 'use-query'; function MyComponent() { const { loading, data, error } = useQuery(async () => { const res = await fetch('https://api.example.com/data'); if (!res.ok) throw new Error('Network error'); return res.json(); }); if (loading) return <div>Loading...</div>; if (error) return <div>Error: {error.message}</div>; return <div>{JSON.stringify(data)}</div>; }
Debug
Known issues
gotchauseQuery does no caching or deduplication; every render triggers a new fetch if no re-fetch guard is used.
fix
Implement manual caching via React state or use a library like SWR/React Query for automatic deduplication.
affects: >=1.0.0
gotchaThe query function is re-created on every render, causing infinite re-fetches if passed inline without memoization.
fix
Wrap the async function in useCallback or define it outside the component.
affects: >=1.0.0
deprecatedThis package is extremely minimal; consider using more robust solutions like @tanstack/react-query for complex data fetching.
fix
Migrate to react-query or swr for caching, deduplication, and better performance.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot read property 'data' of null
Accessing data before first fetch completes
fix
Check loading state before using data, or use optional chaining: data?.property
Maximum update depth exceeded
Query function created inline on every render causing infinite loop
fix
Stabilize the query function with useCallback or a ref
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies
reactoptionalPeer dependency for React hooks and JSX
Agent activity
6 hits · last 30 days
node
6
Resources
use-query — npm install use-query · libregistry