Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/llms-txt-hub / apps/web/hooks/use-websites.ts |
| Date | Not specified in source |
| Repository | Janady13/llms-txt-hub |
| Revision | e0f4bf978d4df168369c7601d9c5f5ea89e84377 |
| Branch | main |
| Path or archive member | apps/web/hooks/use-websites.ts |
| Original SHA-256 | 88f7d240b39a7de20ab951b5e687ee209098463840bcfbb48cacc7e0006d81a1 |
| Git blob SHA | fb3b8d7e3e258e03d44e76275f12a5f94dc41c1e |
| Reading-copy SHA-256 | 88f7d240b39a7de20ab951b5e687ee209098463840bcfbb48cacc7e0006d81a1 |
Recovered source transcript
Download complete source text ↓46 lines · 1.2 KB
'use client'
import { logger } from '@thedaviddias/logging'
import { useEffect, useState } from 'react'
import type { WebsiteMetadata } from '@/lib/content-loader'
/**
* Hook that fetches and manages the list of websites from the API
*/
export function useWebsites() {
const [websites, setWebsites] = useState<WebsiteMetadata[]>([])
const [isLoading, setIsLoading] = useState(true)
const [error, setError] = useState<string | null>(null)
useEffect(() => {
/**
* Fetches the list of websites from the API
*/
async function fetchWebsites() {
try {
setIsLoading(true)
const response = await fetch('/api/websites')
if (!response.ok) {
throw new Error('Failed to fetch websites')
}
const data = await response.json()
setWebsites(data)
setError(null)
} catch (err) {
logger.error('Error fetching websites:', { data: err, tags: { type: 'hook' } })
setError(err instanceof Error ? err.message : 'Failed to fetch websites')
} finally {
setIsLoading(false)
}
}
fetchWebsites()
}, [])
return {
websites,
isLoading,
error
}
}