Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-query

Package Overview
Dependencies
Maintainers
1
Versions
489
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-query

Hooks for managing, caching and syncing asynchronous and remote data in React

  • 2.26.4
  • release-2.x
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.3M
decreased by-11.59%
Maintainers
1
Weekly downloads
 
Created

What is react-query?

The react-query npm package is a powerful tool for fetching, caching, and updating asynchronous data in React applications. It provides hooks that enable efficient data synchronization with your server's state without the need to manage complex state logic within your components.

What are react-query's main functionalities?

Data Fetching

Use the useQuery hook to fetch data from an API and provide the status of the request. It automatically caches the data and provides a re-fetch mechanism.

const { data, error, isLoading } = useQuery('todos', fetchTodos)

Data Mutation

Use the useMutation hook to create or update data. It integrates with the query cache to automatically update related queries on success.

const mutation = useMutation(newTodo => axios.post('/todos', newTodo), { onSuccess: () => queryClient.invalidateQueries('todos') })

Automatic Refetching

Configure queries to refetch automatically under certain conditions, such as when the window regains focus, to keep data fresh.

const { data } = useQuery('todos', fetchTodos, { refetchOnWindowFocus: true })

Pagination and Infinite Queries

Handle paginated or infinite data sets with useInfiniteQuery, which provides functions to fetch additional pages of data.

const { data, fetchNextPage } = useInfiniteQuery('projects', fetchProjects, { getNextPageParam: lastPage => lastPage.nextCursor })

Query Caching and Sharing

Cache query results to optimize performance and reduce the number of requests. Shared queries with the same key will use cached data when possible.

const { data } = useQuery('todos', fetchTodos, { cacheTime: 1000 * 60 * 60 })

Other packages similar to react-query

FAQs

Package last updated on 07 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc