@excentone/spfx-react
Version:
Contains custom ReactJs components and hooks intended to use when developing SharePoint Framework (SPFx) Web components.
14 lines (12 loc) • 602 B
JavaScript
import { useContext, useMemo } from "react";
import { ServiceScopeContext } from "./ServiceScopeContext";
/**
* `useScopedService` returns an instance of a service that matches the specified {@link serviceKey} from the {@link serviceScope}.
* @param serviceKey The key of the service to get.
* @returns A service from the component's`ServiceScope`.
*/
export const useScopedService = (serviceKey) => {
const { serviceScope } = useContext(ServiceScopeContext);
return useMemo(() => serviceScope.consume(serviceKey), [serviceScope]);
};
//# sourceMappingURL=ServiceScopeContext.hooks.js.map