npm install @tanstack/react-query

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

About @tanstack/react-query

The @tanstack/react-query package is a powerful tool for developers using React to handle asynchronous and remote data with ease. It primarily focuses on fetching, caching, and updating data in React applications without the need to touch the global state management. By leveraging this module, developers can keep their applications' UIs and server state synchronized automatically, enhancing the user experience through optimized performance and reduced loading times. The package supports a variety of loading states like loading, error, and success, which helps in managing UI states corresponding to data fetching states seamlessly.

Using @tanstack/react-query improves development efficiency by abstracting common data fetching tasks into reusable React hooks. Developers can implement features such as background updates, pagination, and infinite query loading without extensive boilerplate code. To get started with this robust tool, simply run npm install @tanstack/react-query in your project's terminal. This installation command integrates the package into your project, allowing you to utilize hooks like useQuery and useMutation to fetch and manipulate data respectively. These hooks are designed to handle updates gracefully and reduce the likelihood of data staleness, ensuring that users always have the most current data at their fingertips.

The package also implements automatic refetching strategies which are crucial for maintaining fresh data in real-time applications. With @tanstack/react-query, developers can set precise conditions under which data refetching should occur, such as on window focus or network reconnection. This smart data synchronization eliminates the need for manual refetching triggers, thereby simplifying code and reducing potential errors. As a result, applications remain responsive and efficient, providing end users with a seamless interactive experience.

More from TanStack

TanStack npm packages

Find the best node modules for your project.

Search npm

@tanstack/react-query

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

Read more
,

@tanstack/react-query-devtools

Developer tools to interact with and visualize the TanStack/react-query...

Read more
,

@tanstack/vue-query

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

Read more

Dependencies

Core dependencies of this npm package and its dev dependencies.

@arethetypeswrong/cli, @cspell/eslint-plugin, @solidjs/testing-library, @tanstack/config, @testing-library/jest-dom, @testing-library/react, @types/eslint, @types/node, @types/react, @types/react-dom, @typescript-eslint/eslint-plugin, @typescript-eslint/parser, @vitest/coverage-istanbul, cpy-cli, esbuild-plugin-file-path-extensions, eslint, eslint-config-prettier, eslint-import-resolver-typescript, eslint-plugin-import, eslint-plugin-react, eslint-plugin-react-hooks, husky, jsdom, knip, lint-staged, nx, prettier, prettier-plugin-svelte, publint, react, react-dom, rimraf, sherif, solid-js, tsup, typescript, vite, vitest

Documentation

A README file for the @tanstack/react-query code repository. View Code

TanStack 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! TanStack Table, TanStack Router, TanStack Virtual, React Charts, React Ranger

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

Quick Features

Become a Sponsor!