findmory / react-mobx-hooks

Using Mobx React without inject pattern

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using React with Mobx without Inject

Since the introduction of React Context, the inject pattern is considered obsolete and it's highly recommended to migrate away over time.

Here's a little example I created with a custom React Hook to consume a Mobx Store.

Wherever you need a store just bring it into a functional component such as:

const { sessionStore, userStore } = useStores();

Don't forget to wrap the component in mobx-react : observer

About

Using Mobx React without inject pattern


Languages

Language:JavaScript 62.6%Language:HTML 36.0%Language:CSS 1.4%