Convert Shuffle to mapDispatchToProps

This commit is contained in:
Jordan Eldredge 2016-12-29 21:59:49 -08:00
parent 946537edf7
commit 8c635446a3

View file

@ -3,21 +3,15 @@ import {connect} from 'react-redux';
import classnames from 'classnames';
class Shuffle extends React.Component {
constructor(props) {
super(props);
this.handleClick = this.handleClick.bind(this);
}
handleClick() {
this.props.dispatch({type: 'TOGGLE_SHUFFLE'});
}
render() {
return <div
id='shuffle'
className={classnames({selected: this.props.shuffle})}
onClick={this.handleClick}
/>;
}
}
module.exports = connect((state) => state.media)(Shuffle);
const Shuffle = ({shuffle, toggleShuffle}) => (
<div
id='shuffle'
className={classnames({selected: shuffle})}
onClick={toggleShuffle}
/>
);
const mapStateToProps = (state) => state.media;
const mapDispatchToProps = (dispatch) => ({
toggleShuffle: () => dispatch({type: 'TOGGLE_SHUFFLE'})
});
module.exports = connect(mapStateToProps, mapDispatchToProps)(Shuffle);