"use client"; import { useState, useEffect, useCallback } from "react"; // Generic data type for 餐计划 type Item = Record; /** * Fetch and manage 餐计划 data. */ export function useItem() { const [data, setData] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const fetchData = useCallback(async () => { try { setLoading(true); setError(null); const res = await fetch(`/api/餐计划`); const json = await res.json(); setData(Array.isArray(json) ? json : json?.data || []); } catch (e) { setError(e instanceof Error ? e.message : "Failed to load data"); } finally { setLoading(false); } }, []); useEffect(() => { fetchData(); }, [fetchData]); return { data, loading, error, refetch: fetchData }; }