@defer/client
Advanced tools
Changelog
1.7.0
#66 b9973d5
Thanks @charlypoly! - Introducing @defer/client/next
integration
This release introduces two new helpers that makes Defer deeply integrated with NextJS:
asNextRoute()
: used in combination of useDeferRoute()
to trigger background functions from Client-side ComponentsuseDeferRoute()
: trigger and wait for the result of a background functions from Client-side Componentsimport { asNextRoute } from "@defer/client/next";
import createThumbnails from "../../defer/createThumbnails";
const { GetHandler, PostHandler } = asNextRoute(createThumbnails);
export const GET = GetHandler;
export const POST = PostHandler;
import { useDeferRoute } from "@defer/client/next";
import createThumbnails from "../../defer/createThumbnails";
export function MyComp() {
const { request, loading, result } = useDeferRoute(createThumbnails);
return (
<div>
<span>Loading: {loading ? "Yes" : "No"}</span>
<span>Result: {result ? JSON.stringify(result) : "--"}</span>
<button onClick={() => request("")}>Call</button>
</div>
);
}