import { useEffect, useState } from "react"; import { useApi, useApiQuery } from "bknd/client"; import { Scrollable } from "ui/layouts/AppShell/AppShell"; function Bla() { const api = useApi(); useEffect(() => { (async () => { const one = await api.data.readOne("users", 1); const many = await api.data.readMany("users"); })(); }, []); return null; } export default function SWRAndAPI() { const [text, setText] = useState(""); const { data, ...r } = useApiQuery((api) => api.data.readOne("comments", 1), { refine: (data) => data.data, revalidateOnFocus: true, }); const comment = data ? data : null; useEffect(() => { setText(comment?.content ?? ""); }, [comment]); return (
{JSON.stringify(r.key)}
{r.error &&
failed to load
} {r.isLoading &&
loading...
} {data &&
{JSON.stringify(data, null, 2)}
} {data && (
{ e.preventDefault(); if (!comment) return; /*await r.mutate(async () => { const res = await r.api.data.updateOne("comments", comment.id, { content: text }); return res.data; });*/ return false; }} > setText(e.target.value)} />
)}
); }