Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@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 187,315 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 0 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.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.