Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
@tanstack/query-sync-storage-persister
Advanced tools
A persister for synchronous storages, to be used with TanStack/Query
@tanstack/query-sync-storage-persister is a package designed to persist TanStack Query cache data to various storage solutions, such as localStorage or sessionStorage. This allows for the state of queries to be saved and restored, providing a more seamless user experience across sessions.
Persisting Query Cache to Local Storage
This feature allows you to persist the query cache to the local storage. The code sample demonstrates how to set up the persister with localStorage and integrate it with the TanStack Query client.
const { persistQueryClient } = require('@tanstack/query-sync-storage-persister');
const { QueryClient, QueryCache } = require('@tanstack/react-query');
const { createSyncStoragePersister } = require('@tanstack/query-sync-storage-persister');
const queryClient = new QueryClient({
queryCache: new QueryCache(),
});
const localStoragePersister = createSyncStoragePersister({
storage: window.localStorage,
});
persistQueryClient({
queryClient,
persister: localStoragePersister,
});
Persisting Query Cache to Session Storage
This feature allows you to persist the query cache to the session storage. The code sample demonstrates how to set up the persister with sessionStorage and integrate it with the TanStack Query client.
const { persistQueryClient } = require('@tanstack/query-sync-storage-persister');
const { QueryClient, QueryCache } = require('@tanstack/react-query');
const { createSyncStoragePersister } = require('@tanstack/query-sync-storage-persister');
const queryClient = new QueryClient({
queryCache: new QueryCache(),
});
const sessionStoragePersister = createSyncStoragePersister({
storage: window.sessionStorage,
});
persistQueryClient({
queryClient,
persister: sessionStoragePersister,
});
redux-persist is a library used to persist and rehydrate a Redux store. It provides similar functionality in terms of persisting state to storage solutions like localStorage or sessionStorage. However, it is designed specifically for Redux, whereas @tanstack/query-sync-storage-persister is designed for TanStack Query.
localforage is a library that provides a simple API for storing data in various storage solutions, including IndexedDB, WebSQL, and localStorage. While it is not specifically designed for persisting query caches, it can be used in conjunction with other libraries to achieve similar functionality.
idb-keyval is a small library for storing key-value pairs in IndexedDB. It is a lower-level solution compared to @tanstack/query-sync-storage-persister, which is specifically designed for persisting TanStack Query caches. idb-keyval can be used as a building block for more complex persistence solutions.
FAQs
A persister for synchronous storages, to be used with TanStack/Query
The npm package @tanstack/query-sync-storage-persister receives a total of 164,293 weekly downloads. As such, @tanstack/query-sync-storage-persister popularity was classified as popular.
We found that @tanstack/query-sync-storage-persister demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.