Last active
January 21, 2018 17:13
-
-
Save MicroBenz/72933590b235d7c848f78da7a83c14a0 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 => ({ | |
displayList: props.campers.filter(camper => camper.role === props.displayRole) | |
}) | |
), | |
lifecycle({ | |
componentDidMount() { | |
this.props.loadCampers(); | |
} | |
}) | |
); | |
const Campers = props => { | |
const { displayList, 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> | |
<CamperTable lists={displayList} /> | |
</div> | |
); | |
}; | |
export default enhance(Campers); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment