Use factory

This commit is contained in:
Chi Vinh Le
2017-08-25 19:40:55 +07:00
parent 6ae68a4f90
commit 9e2f6f1f63
10 changed files with 20 additions and 43 deletions
@@ -0,0 +1,4 @@
import withSortOption from '../hocs/withSortOption';
import SortOption from '../components/SortOption';
export const createSortOption = (label, sort) => withSortOption({...sort, label})(SortOption);
@@ -18,14 +18,14 @@ const mapDispatchToProps = (dispatch) =>
dispatch
);
export default ({by = 'created_at', order = 'DESC', label}) => hoistStatics((WrappedComponent) => {
export default ({sortBy = 'created_at', sortOrder = 'DESC', label}) => hoistStatics((WrappedComponent) => {
class WithSortOption extends React.Component {
setSort = () => {
this.props.setSort({by, order});
this.props.setSort({sortBy, sortOrder});
}
render() {
const active = this.props.sortOrder === order && this.props.sortBy === by;
const active = this.props.sortOrder === sortOrder && this.props.sortBy === sortBy;
const resolvedLabel = typeof label === 'function' ? label() : label;
return (
<WrappedComponent