@universal-di/react
v0.0.4
Published
Universal Dependency Injection port for React
Downloads
3
Maintainers
Readme
Universal Dependency Injection port for React
Pre-requisites
Contents
DIContextProvider
DIContextProvider
is a React context provider that allows you to provide dependencies to your React DOM.
const application = new DIApplication(AppModule);
<DIContextProvider
injector={application.rootInjector}
>
<ProductListComponent />
</DIContextProvider>
useInjection
useInjection
is a hook that allows you to inject dependencies into your React components.
export function ProductListComponent() {
// AnalyticsService type is inferred here
const analyticsService = useInjection(ANALYTICS_SERVICE);
useEffect(() => {
analyticsService.track('browsed-productes');
}, []);
}