Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use @inject without decorators #250

Closed
gate3 opened this issue Apr 30, 2017 · 10 comments
Closed

How to use @inject without decorators #250

gate3 opened this issue Apr 30, 2017 · 10 comments

Comments

@gate3
Copy link

@gate3 gate3 commented Apr 30, 2017

Hi, this is a wonderful project you have here, thank you very much. I wish to use @Inject without decorator. I am using create-react-app and it doesn't allow generators. Please any help will be greatly appreciated.

@urugator

This comment has been minimized.

Copy link

@urugator urugator commented Apr 30, 2017

It's in the README

@gate3

This comment has been minimized.

Copy link
Author

@gate3 gate3 commented Apr 30, 2017

@jamiewinder

This comment has been minimized.

@gate3

This comment has been minimized.

Copy link
Author

@gate3 gate3 commented May 1, 2017

@reywright

This comment has been minimized.

Copy link

@reywright reywright commented Oct 27, 2017

how would you inject and observe on a class? That isn't in the readme.

@urugator

This comment has been minimized.

Copy link

@urugator urugator commented Oct 27, 2017

The observer component observes observable things, which are accessed in render. Detailed explanation

@reywright

This comment has been minimized.

Copy link

@reywright reywright commented Oct 27, 2017

This was what I was looking for. I'll leave this here for anyone who is searching

// Stateless Functional
const App = inject("store")(
  observer(({ store }) => (
    <div>{store.foo}</div>
  ))
);

// Class
class App extends Component {
  /* class code here */
}
App = inject('store')(observer(App))

To do this, you'll need to use <Provider /> from mobx-react and put "store" on it.

@Lunada

This comment has been minimized.

Copy link

@Lunada Lunada commented Jul 25, 2018

Hi @reywright . How to perform
App = inject('store')(observer(App))
Since App is not a variable?

This way?

var AppInstance = new App();
AppInstance = inject('store')(observer(AppInstance));
export default AppInstance
@mweststrate

This comment has been minimized.

Copy link
Member

@mweststrate mweststrate commented Jul 26, 2018

@Lunada no, it is the class that needs decorating, not the instance, so:

class _App extends Component {
  /* class code here */
}
const App = inject('store')(observer(_App))

Typically this is done:

class App extends Component {
  /* class code here */
}
export default inject('store')(observer(App))
@Lunada

This comment has been minimized.

Copy link

@Lunada Lunada commented Jul 27, 2018

@mweststrate Thanks a lot, worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.