Created
January 17, 2018 05:22
-
-
Save phpsmarter/b9d6da5e5dc47db049eac1cecaf1f0c2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
``` | |
const { Component } = React; | |
const { mapProps } = Recompose; | |
const User = ({ name, status }) => | |
<div className="User">{ name }—{ status }</div>; | |
const UserList = ({ users, status }) => | |
<div className="UserList"> | |
<h3>{ status } users</h3> | |
{ users && users.map((user) => <User {...user} />) } | |
</div>; | |
const users = [ | |
{ name: "Tim", status: 'active' }, | |
{ name: "Bob", status: 'active' }, | |
{ name: "Joe", status: 'active' }, | |
{ name: "Jim", status: 'inactive' }, | |
]; | |
const filterByStatus = (status) => mapProps( | |
({ users }) => ({ | |
status, | |
users: users.filter(u => u.status === status) | |
}) | |
); | |
const ActiveUsers = filterByStatus('active')(UserList); | |
const InactiveUsers = filterByStatus('inactive')(UserList); | |
const PendingUsers = filterByStatus('pending')(UserList); | |
const App = () => | |
<div className="App"> | |
<ActiveUsers users={ users } /> | |
<InactiveUsers users={ users } /> | |
<PendingUsers users={ users } /> | |
</div>; | |
``` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment