T
TanStack4mo ago
genetic-orange

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
foreign-sapphire
foreign-sapphire4mo ago
updates take a draft object which you directly mutate — you don't return a copy
genetic-orange
genetic-orangeOP4mo ago
🤦‍♂️ thanks mate

Did you find this page helpful?