UNPKG

react-storage-drafts

Version:

React Drafts is a library for creating, saving, and managing local documents in React applications.

39 lines (38 loc) 1.5 kB
export type TDraftKey = string | number | 'first' | 'last'; export type TDraft = { [key: TDraftKey]: any; }; export declare enum EDraftStatus { CHANGED = "changed", REMOVED = "removed", SYNCED = "synced" } export type TDraftStatus = `${EDraftStatus}`; export interface IDraftsContext { drafts: any[]; count: number; addDraft: (draft: TDraft) => void; clearDrafts: () => void; getDraft: (draftKey: TDraftKey) => TDraft | null; removeDraft: (draftKey: TDraftKey) => void; updateDraft: (draftKey: TDraftKey, changes: TDraft) => void; referenceKey: string; handleSync: () => Promise<void>; } export type TSyncTrigger = 'manual' | 'connection' | 'interval' | 'onChange'; export interface IDraftsProviderProps extends React.PropsWithChildren { onLoadStoredData?: () => Promise<TDraft[]>; onSync?: (drafts: TDraft[]) => Promise<void>; referenceKey?: string; /** Type of event to trigger syncing data to data store. Default is 'connection'. * - 'manual' - sync data only when user calls the sync function (from `useDrafts` hook) * - 'connection' - sync data when the device is connected to the internet * - 'interval' - sync data at a specified interval (in seconds) controlled by `syncInterval` option * - 'onChange' - sync data when the data changes (on additon/modification/removal of a draft) */ syncTrigger?: TSyncTrigger; syncInterval?: number; } export interface IUseDraftProps { draftId: TDraftKey; }