react-dididi
v1.0.2
Published
A simple DI/IoC lib for react.
Downloads
5
Readme
react-dididi
A simple DI/IoC lib for react.
Install
npm install react-dididi
Use
import { Injectable } from "react-dididi";
@Injectable()
export class FooService {
constructor(private readonly barService: BarService) {}
print() {
this.barService.name;
}
}
@Injectable()
export class BarService {
name = "Andy";
}
// main.ts
import { setProvides } from "react-dididi";
import { FooService, BarService } from "xxxx";
setProvides([FooService, BarService]);
import { useInject } from "react-dididi";
const xx: React.FC = () => {
const fooService = useInject(FooService);
useEffect(() => {
fooService.print();
}, []);
};