T
TanStack2mo ago
quickest-silver

Data not updating when you using localStorageCollectionOptions with a custom storage (AsyncStorage)

Hi guys i did create a quick wrapper to use AsyncStorage with localStorageCollection the insert function fine but updates dont trigger a setItem anyway to debug this ? Collection
export const sessionCollection = createCollection(
localStorageCollectionOptions({
storageKey: 'session-key',
storage: tanStackStorage,
storageEventApi: tanStackStorage.storageEventApi,
getKey: (item: SessionItem) => item.id
})
);
export const sessionCollection = createCollection(
localStorageCollectionOptions({
storageKey: 'session-key',
storage: tanStackStorage,
storageEventApi: tanStackStorage.storageEventApi,
getKey: (item: SessionItem) => item.id
})
);
Insert
sessionCollection.insert({id: 'games-updated-at',
updatedAt: new Date().toISOString()
});
sessionCollection.insert({id: 'games-updated-at',
updatedAt: new Date().toISOString()
});
Update
sessionCollection.update('games-updated-at', item => ({
...item,
updatedAt: new Date().toISOString()
}));
sessionCollection.update('games-updated-at', item => ({
...item,
updatedAt: new Date().toISOString()
}));
2 Replies
genetic-orange
genetic-orange2mo ago
updates take a draft object which you directly mutate — you don't return a copy
quickest-silver
quickest-silverOP2mo ago
🤦‍♂️ thanks mate

Did you find this page helpful?