这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { AtomEffect } from 'recoil'

interface Storage {
setItem(key: string, value: string): void | Promise<any>
getItem(key: string): null | string | Promise<any>
export interface PersistStorage {
setItem(key: string, value: string): void | Promise<void>

getItem(key: string): null | string | Promise<string>
}

export interface PersistConfiguration {
key?: string
storage?: Storage
storage?: PersistStorage
}

/**
Expand All @@ -24,7 +25,8 @@ export const recoilPersist = (

if (typeof window === 'undefined') {
return {
persistAtom: () => {},
persistAtom: () => {
},
}
}

Expand Down Expand Up @@ -76,6 +78,8 @@ export const recoilPersist = (

const setState = (state: any): void => {
try {
//TODO for React Native `AsyncStorage`, we should be using `mergeItem`
// to merge existing stringified object with new one
storage.setItem(key, JSON.stringify(state))
} catch (e) {
console.error(e)
Expand Down
Loading