Skip to content

Commit

Permalink
KL-178/fix: fetch Like Data
Browse files Browse the repository at this point in the history
- 렌더링 시 Like Data를 fetch하지 않는 버그가 발생하여 수정하였습니다.
  • Loading branch information
seoulyego committed Sep 24, 2024
1 parent 003dc82 commit 967ecc0
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/components/Button/LikeButton.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import React from 'react' // useState,
import React, {
// useState,
useEffect,
} from 'react'
import PropTypes from 'prop-types'
import { FaHeart, FaRegHeart } from 'react-icons/fa6'
import useUserData from '../../hooks/useUserData'
Expand All @@ -14,7 +17,7 @@ function LikeButton({
}) {
const { data: userData } = useUserData()
// const [isLiked, setIsLiked] = useState(likeContent)
const { data: isLiked } = useKyQuery(
const { data: isLiked, refetch: getLike } = useKyQuery(
`products/${productId}/likes`,
null,
[`products/likes`, productId],
Expand All @@ -36,6 +39,19 @@ function LikeButton({
['products/likes', productId]
)

useEffect(() => {
const fetchLikeContent = async () => {
try {
await getLike()
} catch (error) {
console.error(error)
}
}

if (!userData) return
fetchLikeContent()
}, [])

const handleLike = async () => {
const postLikeContent = async () => {
try {
Expand Down

0 comments on commit 967ecc0

Please sign in to comment.