Skip to content

Instantly share code, notes, and snippets.

@flipjs
Last active June 3, 2016 08:01
Show Gist options
  • Save flipjs/d7ba2428b010805b61b18c9888f768ba to your computer and use it in GitHub Desktop.
Save flipjs/d7ba2428b010805b61b18c9888f768ba to your computer and use it in GitHub Desktop.
MobX - Injecting store to components
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