Skip to content

Instantly share code, notes, and snippets.

@MicroBenz
Last active January 21, 2018 17:13
Show Gist options
  • Save MicroBenz/72933590b235d7c848f78da7a83c14a0 to your computer and use it in GitHub Desktop.
Save MicroBenz/72933590b235d7c848f78da7a83c14a0 to your computer and use it in GitHub Desktop.
Recompose
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