Loading...
); if (error) return (Error fetching data.
); @@ -43,6 +86,11 @@ function PersonCard({ index, isFavorite, onFavoriteToggle }: PersonCardProps): J } const handleFavoriteClick = () => { + if (isFavorite) { + deleteMutation.mutate(); + } else { + addMutation.mutate(data); + } onFavoriteToggle(index); }; @@ -54,6 +102,7 @@ function PersonCard({ index, isFavorite, onFavoriteToggle }: PersonCardProps): J variant={isFavorite ? 'primary' : 'outline-primary'} value={1} onClick={handleFavoriteClick} + disabled={addMutation.isLoading || deleteMutation.isLoading} > {isFavorite ? 'Unfavorite' : 'Favorite'}