MobX React Typed Injection
A better, fully typed injector HOC to use with MobX and React.
!!! Deprecated !!!
This package is deprecated in favor of using MobX with hooks instead.
Benefits
- The inject function "knows" your stores, so you'll have proper TS code completion and warnings for non-matching types
- Build time errors when trying to use props that are already injected
- No need to add one more context provider to your app root
Install it
yarn add mobx-react-typed-injection
Use it
-
Somewhere in your project, create a
stores.ts
file, exportinginject
andwithFakeStores
(to be used on tests): -
Inject something from the stores into a dumb component:
-
Use your injected component:
// Works fine for non injected propsMovieHeader somethingElse="lorem ipsum"/// TS error for props already injectedMovieHeader title="lorem ipsum"/