fix: pass initial count to hooks for correct optimistic update
- Add initialLikeCount and initialFavoriteCount parameters - Use item.likeCount/item.favoriteCount as fallback - Fixes issue where count resets to 0 on first click
This commit is contained in:
@@ -92,8 +92,8 @@ export const VideoItem = memo(({ item, videoHeight }: { item: TemplateDetail; vi
|
||||
const favoriteCount = useTemplateFavoriteCount(item.id) ?? item.favoriteCount
|
||||
|
||||
// 使用 hooks 获取操作函数
|
||||
const { like: onLike, unlike: onUnlike, loading: likeLoading } = useTemplateLike(item.id)
|
||||
const { favorite: onFavorite, unfavorite: onUnfavorite, loading: favoriteLoading } = useTemplateFavorite(item.id)
|
||||
const { like: onLike, unlike: onUnlike, loading: likeLoading } = useTemplateLike(item.id, item.likeCount)
|
||||
const { favorite: onFavorite, unfavorite: onUnfavorite, loading: favoriteLoading } = useTemplateFavorite(item.id, false, item.favoriteCount)
|
||||
|
||||
const handleImageLoad = useCallback((event: ImageLoadEventData) => {
|
||||
const { source } = event
|
||||
|
||||
Reference in New Issue
Block a user