UNPKG

alepha

Version:

Easy-to-use modern TypeScript framework for building many kind of applications.

23 lines (20 loc) 558 B
import { type ClientScope, type HttpVirtualClient, LinkProvider, } from "alepha/server/links"; import { useMemo } from "react"; import { useInject } from "./useInject.ts"; /** * Hook to get a virtual client for the specified scope. * * It's the React-hook version of `$client()`, from `AlephaServerLinks` module. */ export const useClient = <T extends object>( scope?: ClientScope, ): HttpVirtualClient<T> => { const linkProvider = useInject(LinkProvider); return useMemo(() => { return linkProvider.client<T>(scope); }, [scope]); };