-
-
Save williamtran29/158763aae8fad605a5a4bf5ba2676589 to your computer and use it in GitHub Desktop.
recompose
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 User from './User'; | |
import { connect } from 'react-redux'; | |
import { fetchUsers } from '../actions/index'; | |
import { lifecycle, compose } from 'recompose'; | |
const enhance = compose( | |
lifecycle({ | |
componentDidMount() { | |
this.props.fetchUsers(); | |
} | |
}) | |
) | |
export const UserList = ({ users }) => ( | |
<ul className="userlist"> | |
{users.map((user, i) => <User key={i} {...user} />)} | |
</ul> | |
); | |
const mapStateToProps = ({ users }) => ({ users }); | |
export default connect(mapStateToProps, {fetchUsers})(enhance(UserList)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment