useIncrementEntity: fix optimistic counter

This commit is contained in:
Alex Gleason 2023-03-22 19:58:40 -05:00
parent 402daec9c3
commit 6929975aaa
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -21,9 +21,9 @@ function useIncrementEntity<T = unknown>(
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
return async function incrementEntity(entityId: string): Promise<void> { return async function incrementEntity(entityId: string): Promise<void> {
dispatch(incrementEntities(entityType, listKey, diff));
try { try {
await incrementFn(entityId); await incrementFn(entityId);
dispatch(incrementEntities(entityType, listKey, diff));
} catch (e) { } catch (e) {
dispatch(incrementEntities(entityType, listKey, diff * -1)); dispatch(incrementEntities(entityType, listKey, diff * -1));
} }