Socket
Socket
Sign inDemoInstall

@tanstack/query-core

Package Overview
Dependencies
0
Maintainers
2
Versions
223
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @tanstack/query-core

The framework agnostic core that powers TanStack Query


Version published
Weekly downloads
3.3M
increased by5.16%
Maintainers
2
Install size
1.79 MB
Created
Weekly downloads
 

Package description

What is @tanstack/query-core?

The @tanstack/query-core package is a lightweight and powerful data synchronization library for JavaScript. It enables efficient server state management by providing hooks and utilities to fetch, cache, and update data in React applications. The core package is framework-agnostic and can be used with any JavaScript framework or UI layer.

What are @tanstack/query-core's main functionalities?

Data Fetching

This feature allows you to fetch data from an API or any asynchronous source. The useQuery hook returns the data, error, and loading state, making it easy to build UI components that react to data fetching state.

import { QueryClient, QueryCache, useQuery } from '@tanstack/query-core';

const queryClient = new QueryClient({
  queryCache: new QueryCache(),
});

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

Data Caching

Data caching enables efficient data retrieval by storing fetched data in a cache. This reduces the need for unnecessary network requests, as subsequent requests for the same data can be served from the cache.

import { QueryClient, QueryCache } from '@tanstack/query-core';

const queryClient = new QueryClient({
  queryCache: new QueryCache(),
});

queryClient.setQueryData(['todos'], updatedTodos);

Data Mutation

Data mutation is the process of updating data on the server and then synchronizing the updated data with the client. The useMutation hook is used to perform mutations, and it provides callbacks such as onSuccess to handle side effects like invalidating the cache to refetch updated data.

import { QueryClient, QueryCache, useMutation } from '@tanstack/query-core';

const queryClient = new QueryClient({
  queryCache: new QueryCache(),
});

const mutation = useMutation(addTodo, {
  onSuccess: () => {
    queryClient.invalidateQueries(['todos']);
  },
});

Other packages similar to @tanstack/query-core

FAQs

Last updated on 23 Apr 2024

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