@scaffold-ai/react-service-provider
Version:
React context-based service provider for dependency injection.
17 lines (16 loc) • 829 B
TypeScript
import { Service } from './Service';
/**
* A custom hook for retrieving a specific service instance by its unique identifier.
*
* This function must be used within the context of a `ServiceProvider`. It provides a way
* to access dependencies or services that have been registered in the application's service context.
*
* @template T The type of the service being retrieved.
* @param {Symbol} serviceId The unique identifier of the service to retrieve.
* @returns {T} The service instance matching the provided `serviceId`.
* @throws {Error} Throws an error if the hook is used outside a `ServiceProvider`.
* @throws {Error} Throws an error if no service with the specified `serviceId` is found.
* @see ServiceProvider
* @see Service
*/
export declare const useService: <T extends Service>(serviceId: symbol) => T;