0.0.19 • Published 1 year ago

@shared-state/persist v0.0.19

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@shared-state/persist

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

快速开始

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

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

示例

使用 localStorage 或 sessionStorage 持久化状态

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

const localStoragePersistentState = persist(createSharedState(0), {
  key: "localStorage",
  storage: createWebPersistentStorage(localStorage),
});

const sessionStoragePersistentState = persist(createSharedState(0), {
  key: "sessionStorage",
  storage: createWebPersistentStorage(sessionStorage),
});

监听持久化数据加载状态

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

const persistentState = persist(createSharedState(0), {
  key: "localStorage",
  storage: createWebPersistentStorage(localStorage),
});

persistentState.hydrationState.subscribe((hydrating) => console.log(hydrating));
0.0.18

1 year ago

0.0.19

1 year ago

0.0.10

1 year ago

0.0.11

1 year ago

0.0.12

1 year ago

0.0.13

1 year ago

0.0.14

1 year ago

0.0.15

1 year ago

0.0.9

1 year ago

0.0.16

1 year ago

0.0.8

1 year ago

0.0.17

1 year ago

0.0.5

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

2 years ago