UNPKG

remix-utils

Version:

This package contains simple utility functions to use with [React Router](https://reactrouter.com/).

25 lines (24 loc) 1.19 kB
import type { unstable_MiddlewareFunction, unstable_RouterContextProvider } from "react-router"; import type { Class } from "type-fest"; /** * Creates a singleton middleware that creates an instance of a class and stores * it in the context. If the instance already exists in the context, it will * return the existing instance. * * @param options - Options for the singleton middleware. * @param options.Class - The class to create an instance of. * @param options.arguments - Arguments to pass to the class constructor. * @returns A tuple containing the middleware function and a function to get the * singleton instance from the context. */ export declare function unstable_createSingletonMiddleware<T, A extends unknown[] = any[]>(options: unstable_createSingletonMiddleware.Options<T, A>): unstable_createSingletonMiddleware.ReturnType<T>; export declare namespace unstable_createSingletonMiddleware { interface Options<T, A extends unknown[] = any[]> { Class: Class<T, A>; arguments: A; } type ReturnType<T> = [ unstable_MiddlewareFunction<unstable_RouterContextProvider>, (context: unstable_RouterContextProvider) => T ]; }