mirror of
https://github.com/privacy-scaling-explorations/pse.dev.git
synced 2026-01-10 06:38:03 -05:00
feat: youtube feed (#374)
- [x] add PSE youtube channel youtube feed in homepage
This commit is contained in:
26
hooks/useYoutube.ts
Normal file
26
hooks/useYoutube.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { useQuery } from "@tanstack/react-query"
|
||||
|
||||
async function fetchYoutubeVideos() {
|
||||
try {
|
||||
const response = await fetch("/api/youtube", {
|
||||
cache: "default",
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch videos: ${response.status}`)
|
||||
}
|
||||
|
||||
const data = await response.json()
|
||||
return data.videos || []
|
||||
} catch (error) {
|
||||
console.error("Error fetching videos:", error)
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
export const useYoutube = () => {
|
||||
return useQuery({
|
||||
queryKey: ["pse-youtube-videos"],
|
||||
queryFn: () => fetchYoutubeVideos(),
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user