function localStorageCollectionOptions<TExplicit, TSchema, TFallback>(config): object
function localStorageCollectionOptions<TExplicit, TSchema, TFallback>(config): object
Defined in: packages/db/src/local-storage.ts:205
Creates localStorage collection options for use with a standard Collection
This function creates a collection that persists data to localStorage/sessionStorage and synchronizes changes across browser tabs using storage events.
• TExplicit = unknown
The explicit type of items in the collection (highest priority)
• TSchema extends StandardSchemaV1<unknown, unknown> = never
The schema type for validation and type inference (second priority)
• TFallback extends object = Record<string, unknown>
The fallback type if no explicit or schema type is provided
LocalStorageCollectionConfig<TExplicit, TSchema, TFallback>
Configuration options for the localStorage collection
object
Collection options with utilities including clearStorage and getStorageSize
getKey: (item) => string | number;
getKey: (item) => string | number;
string | number
id: string = collectionId;
id: string = collectionId;
onDelete: (params) => Promise<any> = wrappedOnDelete;
onDelete: (params) => Promise<any> = wrappedOnDelete;
DeleteMutationFnParams<ResolveType<TExplicit, TSchema, TFallback>>
Promise<any>
onInsert: (params) => Promise<any> = wrappedOnInsert;
onInsert: (params) => Promise<any> = wrappedOnInsert;
InsertMutationFnParams<ResolveType<TExplicit, TSchema, TFallback>>
Promise<any>
onUpdate: (params) => Promise<any> = wrappedOnUpdate;
onUpdate: (params) => Promise<any> = wrappedOnUpdate;
UpdateMutationFnParams<ResolveType<TExplicit, TSchema, TFallback>>
Promise<any>
optional schema: TSchema;
optional schema: TSchema;
sync: SyncConfig<ResolveType<TExplicit, TSchema, TFallback>, string | number> & object;
sync: SyncConfig<ResolveType<TExplicit, TSchema, TFallback>, string | number> & object;
optional manualTrigger: () => void;
optional manualTrigger: () => void;
void
utils: object;
utils: object;
clearStorage: ClearStorageFn;
clearStorage: ClearStorageFn;
getStorageSize: GetStorageSizeFn;
getStorageSize: GetStorageSizeFn;
// Basic localStorage collection
const collection = createCollection(
localStorageCollectionOptions({
storageKey: 'todos',
getKey: (item) => item.id,
})
)
// Basic localStorage collection
const collection = createCollection(
localStorageCollectionOptions({
storageKey: 'todos',
getKey: (item) => item.id,
})
)
// localStorage collection with custom storage
const collection = createCollection(
localStorageCollectionOptions({
storageKey: 'todos',
storage: window.sessionStorage, // Use sessionStorage instead
getKey: (item) => item.id,
})
)
// localStorage collection with custom storage
const collection = createCollection(
localStorageCollectionOptions({
storageKey: 'todos',
storage: window.sessionStorage, // Use sessionStorage instead
getKey: (item) => item.id,
})
)
// localStorage collection with mutation handlers
const collection = createCollection(
localStorageCollectionOptions({
storageKey: 'todos',
getKey: (item) => item.id,
onInsert: async ({ transaction }) => {
console.log('Item inserted:', transaction.mutations[0].modified)
},
})
)
// localStorage collection with mutation handlers
const collection = createCollection(
localStorageCollectionOptions({
storageKey: 'todos',
getKey: (item) => item.id,
onInsert: async ({ transaction }) => {
console.log('Item inserted:', transaction.mutations[0].modified)
},
})
)