Usually React is responsible for creating and managing a component. How did you make that magic happen regardless those restrictions?
We don’t do any magic. React components usually exist outside of the DI context. Because of it though we avoid using it, normally have an injectable widget with template methods for rendering, look for instance at
Ty for the fast reply. Unfortunately React doesn’t have a good DI concept itself, just the context API which is usable only within React. I hoped to see some magic
So other ways to use DI in a normal React Component (within one single React app) is to either
- use @lazyInject property injection or
- call the ioc-container get/resolve-methods directly or
- use a proxy for 2) to be decoupled from the concrete ioc-container or
- use a custom useInjection()-hook in case you use functional components which is similar to 3) but uses the context API