Last active
January 12, 2018 09:35
-
-
Save MicroBenz/6ac2a4ec457213c75bf9e5d0f6e13f2c to your computer and use it in GitHub Desktop.
Recompose
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 { conenct } from 'react-redux'; | |
import { compose, lifecycle, branch, renderComponent, withProps, withState } from 'recompose'; | |
import { loadCampers } from 'redux/campers/actions'; | |
const enhance = compose( | |
connect( | |
state => ({ | |
campers: state.campers.lists | |
}), | |
{ loadCampers } | |
), | |
branch(props => props.loading, renderComponent(Loader)), | |
withState('displayRole', 'setDisplayRole', 'design'), | |
withProps( | |
props => ({ | |
design: props.campers.filter(camper => camper.role === 'design'), | |
marketing: props.campers.filter(camper => camper.role === 'marketing'), | |
programming: props.campers.filter(camper => camper.role === 'programming'), | |
content: props.campers.filter(camper => camper.role === 'content'), | |
}) | |
), | |
lifecycle({ | |
componentDidMount() { | |
this.props.loadCampers(); | |
} | |
}) | |
); | |
const Campers = props => { | |
const { design, marketing, programming, content, displayRole, setDisplayRole } = props; | |
return ( | |
<div> | |
<button onClick={() => setDisplayRole('design')}>Design</button> | |
<button onClick={() => setDisplayRole('Marketing')}>Marketing</button> | |
<button onClick={() => setDisplayRole('Programming')}>Programming</button> | |
<button onClick={() => setDisplayRole('Content')}>Content</button> | |
{displayRole === 'design' && <CamperTable lists={design} />} | |
{displayRole === 'marketing' && <CamperTable lists={marketing} />} | |
{displayRole === 'programming' && <CamperTable lists={programming} />} | |
{displayRole === 'content' && <CamperTable lists={content} />} | |
</div> | |
); | |
}; | |
export default enhance(Campers); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment