Skip to content

Instantly share code, notes, and snippets.

@cavinsmith
Created October 4, 2017 10:41
Show Gist options
  • Save cavinsmith/dfb8d145af4e21c8b895e89811f23e84 to your computer and use it in GitHub Desktop.
Save cavinsmith/dfb8d145af4e21c8b895e89811f23e84 to your computer and use it in GitHub Desktop.
import { Component } from 'react'
// Our connector decorator
import { connect } from 'redux-getters'
// We need to have store list as constants e.g. USERS: 'users'
// Probably we can do it in store index file export
import STORES from 'reducers/index'
// Setters are redux dispatched actions as is
import { addUser } from 'actions/setters/users'
// As in flux we need to subscribe to some stores
const SELECTED_STORES = [
STORES.AUTH,
STORES.USERS,
]
// Setters are redux dispatched actions as is
const mapDispatchToProps = ({
addUser: addUser
})
@connect(SELECTED_STORES, mapDispatchToProps)
export default class Something extends Component {
render() {
const { getters, userId } = this.props
const { isLoggedIn } = getters[STORES.AUTH]
const { getUser }
return (
<div>
{ isLoggedIn && 'You're logged in!' }
{ !isLoggedIn && 'You're anonymous' }
<UserCard user={getUser(userId)} />
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment