Last active
June 3, 2016 08:01
-
-
Save flipjs/d7ba2428b010805b61b18c9888f768ba to your computer and use it in GitHub Desktop.
MobX - Injecting store to components
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import { observer } from 'mobx-react' | |
import store from '../store' | |
function UserList (props) { | |
const {users} = props.store | |
return ( | |
<ul> | |
{users.map(user => <li key={user.id}>{user.name}</li>)} | |
</ul> | |
) | |
} | |
UserList.propTypes = { | |
store: React.PropTypes.object | |
} | |
function injectStore (Component) { | |
return (() => <Component store={store} />) | |
} | |
export default injectStore(observer(UserList)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment