Create file src/hooks/useCourses.js

This commit is contained in:
Austin Kelsay 2024-08-02 13:50:43 -05:00
parent a12783270f
commit 83d847ab0c

14
src/hooks/useCourses.js Normal file
View File

@ -0,0 +1,14 @@
import { useQuery } from '@tanstack/react-query';
import axios from 'axios';
const fetchCourses = async () => {
const { data } = await axios.get('/api/courses');
return data;
};
export const useCourses = () => {
return useQuery({
queryKey: ['courses'],
queryFn: fetchCourses,
});
};