Skip to content

Instantly share code, notes, and snippets.

@nabanita-sarkar
Last active February 2, 2022 16:56
Show Gist options
  • Save nabanita-sarkar/9b4aad69f680da4b256005bfd07fea94 to your computer and use it in GitHub Desktop.
Save nabanita-sarkar/9b4aad69f680da4b256005bfd07fea94 to your computer and use it in GitHub Desktop.
// in the component use it just like this
const { isLoading, isError, data } = useGetTodoById(id)
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