78 lines
2.6 KiB
Plaintext
78 lines
2.6 KiB
Plaintext
import { Env, Input, MiddlewareHandler } from "../../types.js";
|
|
import { Context, PropsForRenderer } from "../../context.js";
|
|
import { PropsWithChildren } from "../../jsx/types.js";
|
|
import { Context as Context$1 } from "../../jsx/context.js";
|
|
import { FC } from "../../jsx/base.js";
|
|
//#region src/middleware/jsx-renderer/index.d.ts
|
|
export declare const RequestContext: Context$1<Context<any, any, {}> | null>;
|
|
type RendererOptions = {
|
|
docType?: boolean | string;
|
|
stream?: boolean | Record<string, string>;
|
|
};
|
|
type ComponentResult = Exclude<ReturnType<FC>, null>;
|
|
type ComponentWithChildren = (props: PropsWithChildren<PropsForRenderer & {
|
|
Layout: FC;
|
|
}>, c: Context) => ComponentResult;
|
|
/**
|
|
* JSX Renderer Middleware for hono.
|
|
*
|
|
* @see {@link https://hono.dev/docs/middleware/builtin/jsx-renderer}
|
|
*
|
|
* @param {ComponentWithChildren} [component] - The component to render, which can accept children and props.
|
|
* @param {RendererOptions} [options] - The options for the JSX renderer middleware.
|
|
* @param {boolean | string} [options.docType=true] - The DOCTYPE to be added at the beginning of the HTML. If set to false, no DOCTYPE will be added.
|
|
* @param {boolean | Record<string, string>} [options.stream=false] - If set to true, enables streaming response with default headers. If a record is provided, custom headers will be used.
|
|
* @returns {MiddlewareHandler} The middleware handler function.
|
|
*
|
|
* @example
|
|
* ```ts
|
|
* const app = new Hono()
|
|
*
|
|
* app.get(
|
|
* '/page/*',
|
|
* jsxRenderer(({ children }) => {
|
|
* return (
|
|
* <html>
|
|
* <body>
|
|
* <header>Menu</header>
|
|
* <div>{children}</div>
|
|
* </body>
|
|
* </html>
|
|
* )
|
|
* })
|
|
* )
|
|
*
|
|
* app.get('/page/about', (c) => {
|
|
* return c.render(<h1>About me!</h1>)
|
|
* })
|
|
* ```
|
|
*/
|
|
export declare const jsxRenderer: <E extends Env = Env>(component?: ComponentWithChildren, options?: RendererOptions | ((c: Context<E>) => RendererOptions)) => MiddlewareHandler;
|
|
/**
|
|
* useRequestContext for Hono.
|
|
*
|
|
* @template E - The environment type.
|
|
* @template P - The parameter type.
|
|
* @template I - The input type.
|
|
* @returns {Context<E, P, I>} An instance of Context.
|
|
*
|
|
* @example
|
|
* ```ts
|
|
* const RequestUrlBadge: FC = () => {
|
|
* const c = useRequestContext()
|
|
* return <b>{c.req.url}</b>
|
|
* }
|
|
*
|
|
* app.get('/page/info', (c) => {
|
|
* return c.render(
|
|
* <div>
|
|
* You are accessing: <RequestUrlBadge />
|
|
* </div>
|
|
* )
|
|
* })
|
|
* ```
|
|
*/
|
|
export declare const useRequestContext: <E extends Env = any, P extends string = any, I extends Input = {}>() => Context<E, P, I>;
|
|
//#endregion
|
|
export {};
|