mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-17 12:56:05 +00:00
added useApi and useApiQuery to work seamlessly with SWR (tbc)
This commit is contained in:
20
app/src/ui/routes/test/tests/swr-and-api.tsx
Normal file
20
app/src/ui/routes/test/tests/swr-and-api.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
import { useState } from "react";
|
||||
import { useApiQuery } from "ui/client";
|
||||
import { Scrollable } from "ui/layouts/AppShell/AppShell";
|
||||
|
||||
export default function SWRAndAPI() {
|
||||
const [enabled, setEnabled] = useState(false);
|
||||
const { data, error, isLoading } = useApiQuery(({ data }) => data.readMany("posts"), {
|
||||
enabled,
|
||||
revalidateOnFocus: true
|
||||
});
|
||||
|
||||
return (
|
||||
<Scrollable>
|
||||
<button onClick={() => setEnabled((p) => !p)}>{enabled ? "disable" : "enable"}</button>
|
||||
{error && <div>failed to load</div>}
|
||||
{isLoading && <div>loading...</div>}
|
||||
{data && <pre>{JSON.stringify(data, null, 2)}</pre>}
|
||||
</Scrollable>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user