Skip to content

Commit

Permalink
fix hook
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushtiwari110 committed Aug 5, 2024
1 parent f52e8ec commit 474a8d0
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/services/community-timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,17 @@ export const useUpdateUserPost = () => {
export function useGetUserPosts() {
const [cookieValue] = useCookie('uni_user_token')

const { isLoading, data, error } = useQuery({
const state = useQuery({
queryKey: ['userPosts'],
queryFn: () => getAllUserPosts(cookieValue),
})

let errorMessage = null
if (axios.isAxiosError(error) && error.response) {
errorMessage = error.response.data
if (axios.isAxiosError(state.error) && state.error.response) {
errorMessage = state.error.response.data
}

return { isLoading, data, error: errorMessage }
return { ...state, error: errorMessage }
}

export const useCreateUserPost = () => {
Expand All @@ -152,17 +152,17 @@ export const useCreateUserPost = () => {
export function useGetTimelinePosts() {
const [cookieValue] = useCookie('uni_user_token')

const { isLoading, data, error } = useQuery({
const state = useQuery({
queryKey: ['timelinePosts'],
queryFn: () => getAllTimelinePosts(cookieValue),
})

let errorMessage = null
if (axios.isAxiosError(error) && error.response) {
errorMessage = error.response.data
if (axios.isAxiosError(state.error) && state.error.response) {
errorMessage = state.error.response.data
}

return { isLoading, data, error: errorMessage }
return { ...state, error: errorMessage }
}

export const useLikeUnlikeTimelinePost = () => {
Expand Down

0 comments on commit 474a8d0

Please sign in to comment.