Last active
February 2, 2022 16:56
-
-
Save nabanita-sarkar/9b4aad69f680da4b256005bfd07fea94 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in the component use it just like this | |
const { isLoading, isError, data } = useGetTodoById(id) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const useGetTodoById = (id) => { | |
const { isLoading, isError, data } = useQuery( | |
["todo/detail", id], | |
() => { | |
return axios.get(`http://localhost:4000/todo/detail/:${id}`); | |
}, | |
{ | |
enabled: !!id, | |
retry: 1, | |
onSuccess: () => { | |
// invalidate some query | |
}, | |
onError: () => { | |
// do something else | |
}, | |
} | |
); | |
export { isLoading, isError, data }; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment