import { useCallback, useState } from "preact/hooks"; export function Recommendations({ id, type }: { id: string; type: string }) { const [state, setState] = useState<"disabled" | "loading">( "disabled", ); const [results, setResults] = useState(); const startFetch = useCallback( async () => { if (state === "loading") return; setState("loading"); const res = await fetch(`/api/recommendation/${type}/${id}`); const json = await res.json(); setResults(json); }, [id, type], ); if (results) { return (
{res.title}
Loading...
; } return ; }