How does constructor injection in the React part of Theia work?

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 TreeWidget.

1 Like

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 :slight_smile:

So other ways to use DI in a normal React Component (within one single React app) is to either

  1. use @lazyInject property injection or
  2. call the ioc-container get/resolve-methods directly or
  3. use a proxy for 2) to be decoupled from the concrete ioc-container or
  4. use a custom useInjection()-hook in case you use functional components which is similar to 3) but uses the context API