Why mobx inject needs to use react's context?

749 views Asked by At

What are the potential issues to implement a @inject decorator which does not depend to mobx-react's Provider component (which stores its properties in react's context)?

The usage of the inject would be something like this:

// MyComponent.js

import { authManager } from './services';

const MyComponent = ({ authManager }) => ...;

export default inject({ authManager })(MyComponent);

It just merges its parameter with component props.

1

There are 1 answers

0
webdeb On BEST ANSWER

You can pass a function as the first argument into the inject function. https://github.com/mobxjs/mobx-react#customizing-inject

import { authManager } from './services';
inject(_stores => ({ authManager }))(YouComponent);

It will not depend on the context, it will just map the returned object to your props.

I didn't tested it