Files
vula-5be28755/src/hooks/useVulaContent.ts
T
Vula Builder c89443ed83 Deploy
2026-07-28 07:32:28 +00:00

32 lines
744 B
TypeScript

'use client'
import { useState, useEffect } from 'react'
export interface CmsItem {
id: string
collection: string
title: string | null
data: Record<string, unknown>
status: string
sortOrder: number
scheduledAt: string | null
expiresAt: string | null
publishedAt: string | null
}
export function useVulaContent(collection: string) {
const [items, setItems] = useState<CmsItem[]>([])
const [loading, setLoading] = useState(true)
useEffect(() => {
fetch(`/api/content/${collection}`)
.then(r => r.json())
.then((data: { items?: CmsItem[] }) => {
setItems(data.items ?? [])
setLoading(false)
})
.catch(() => setLoading(false))
}, [collection])
return { items, loading }
}