Socket
Socket
Sign inDemoInstall

react-query

Package Overview
Dependencies
29
Maintainers
1
Versions
489
Alerts
File Explorer

Advanced tools

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


Version published
Weekly downloads
1.4M
increased by4.93%
Maintainers
1
Created
Weekly downloads
Β 

Package description

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

Readme

Source

React Query Header

Hooks for fetching, caching and updating asynchronous data in React

#TanStack semantic-release Join the discussion on Github Best of JS Gitpod Ready-to-Code

Enjoy this library? Try the entire TanStack! React Table, React Form, React Charts

Visit react-query.tanstack.com for docs, guides, API and more!

Still on React Query v2? No problem! Check out the v2 docs here: https://react-query-v2.tanstack.com/.
Would you like to try React Query v4beta? Check out the v4 beta docs here: https://react-query-beta.tanstack.com/.

Quick Features

  • Transport/protocol/backend agnostic data fetching (REST, GraphQL, promises, whatever!)
  • Auto Caching + Refetching (stale-while-revalidate, Window Refocus, Polling/Realtime)
  • Parallel + Dependent Queries
  • Mutations + Reactive Query Refetching
  • Multi-layer Cache + Automatic Garbage Collection
  • Paginated + Cursor-based Queries
  • Load-More + Infinite Scroll Queries w/ Scroll Recovery
  • Request Cancellation
  • React Suspense + Fetch-As-You-Render Query Prefetching
  • Dedicated Devtools
  • (depending on features imported)

Become a Sponsor!

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Tanner Linsley

πŸ’» πŸ€” πŸ’‘ 🚧 πŸ‘€

Andrew Cherniavskii

πŸ’» πŸ›

Thibaut Tiberghien

πŸ“–

Rohit Garg

πŸ”§

Avinash

πŸ’» πŸ›

Jason O'Neill

🚧 ⚠️

Jack Zhao

πŸ’» πŸ›

dpyzo0o

πŸ’»

Jelte Liekens

πŸ’»

Jen Gettings

πŸ’»

Justin

πŸ’»

Marcelo Alves

πŸ’»

Zorza

πŸ“–

Dominik Dorfmeister

πŸ’» πŸ“– 🚧 πŸ’¬ πŸ‘€

Alex Johansson

πŸ’»

Eddy

πŸ’»

Prateek Surana

πŸ’»

Rene Dellefont

πŸ’» πŸ“–

Janne Vuoti

πŸ’»

Arnaud

πŸ’» πŸ“–

Jakub Ε»urawski

πŸ“–

This project follows the all-contributors specification. Contributions of any kind welcome!

FAQs

Last updated on 06 Jun 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc