@vladbasin/ts-dependencies-reactjs
v1.0.8
Published
ReactJS integration for @vladbasin/ts-dependencies
Downloads
6
Readme
ts-dependencies-reactjs
ReactJS integration for @vladbasin/ts-dependencies
Install
npm install @vladbasin/ts-dependencies-reactjs --save
Getting Started
This library integrates @vladbasin/ts-dependencies
library into ReactJS projects
Create ServiceCollection as described in @vladbasin/ts-dependencies
const services = serviceBuilder.build();
Wrap your App with ServiceProvider
import { ServiceProvider } from "@vladbasin/ts-dependencies-reactjs";
export const App = () => {
return (
<ServiceProvider services={services}>
....
</ServiceProvider>
)
}
Use hooks to resolve services in components
import { ServiceProvider } from "@vladbasin/ts-dependencies-reactjs";
//single service resolution
const car = useService<CarInterface>("car"); //typescript
const car = useService("car"); //javascript
//multiple services resolution
const [car, engine] = useServices("car", "engine");