Last active
October 3, 2017 03:57
-
-
Save neroze/77845739b8297691b70e441f32d18616 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
import React from 'react'; | |
import { | |
compose, | |
setDisplayName, | |
setPropTypes, | |
withState, | |
withHandlers, | |
lifecycle, | |
mapProps | |
} from 'recompose' | |
const {Component} = React; | |
const users = [ | |
{name: 'Time', status: 'active'} | |
,{name: 'BOb', status: 'pending'} | |
,{name: 'Joe', status: 'active'} | |
,{name: 'jim', status: 'inactive'} | |
] | |
const User = ({name, status}) => | |
<div> {name} -- {status}</div> | |
const UserList = ({users, status}) => | |
<div className="UserList"> | |
<h3>{status}</h3> | |
{ users && users.map((user) => <User {...user} />)} | |
</div> | |
const filterByStatus = (status) => mapProps( | |
({user}) => ({ | |
status, | |
users: users.filter(u => u.status === status) | |
}) | |
) | |
const ActiveUser = filterByStatus('active')(UserList); | |
const InactiveUser = filterByStatus('inactive')(UserList); | |
const PendingUser = filterByStatus('pending')(UserList); | |
const App = () => | |
<div className="app"> | |
<ActiveUser users={users} /> | |
<InactiveUser users={users} /> | |
<PendingUser users={users} /> | |
<hr /> | |
</div> | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment