@shared-state/persistence
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

@shared-state/persistence

此软件包提供状态持久化功能

快速开始

Install @shared-state/core and @shared-state/persistence

pnpm install @shared-state/core @shared-state/persistence

示例

使用 localStorage 或 sessionStorage 持久化状态

import {
  createPersistenceSharedState,
  createWebPersistenceStorage,
} from "@shared-state/persistence";

const localStoragePersistenceState = createPersistenceSharedState(
  createWebPersistenceStorage(localStorage),
  "localStorage",
  0
);

const sessionStoragePersistenceState = createPersistenceSharedState(
  createWebPersistenceStorage(sessionStorage),
  "sessionStorage",
  0
);

监听持久化数据加载状态

import { createSharedState } from "@shared-state/core";
import { persist, createWebPersistenceStorage } from "@shared-state/persistence";

const persistenceState = createPersistenceSharedState(
  createWebPersistenceStorage(localStorage),
  "localStorage",
  0
);

persistenceState.hydrationState.subscribe((hydrating) => console.log(hydrating));

Readme

Keywords

Package Sidebar

Install

npm i @shared-state/persistence

Weekly Downloads

158

Version

1.2.0

License

MIT

Unpacked Size

24.2 kB

Total Files

9

Last publish

Collaborators

  • lmarklil