Files
SnowLuma/.pnpm-store/v11/files/87/58998a2e37284657ebc9f40767215d4f7cc5b3de5d39c89529f10e825ee7abc2ae03226b3fac25504848347950416a08de7e0480e10f904a6468c67980c355
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

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 {};