Skip to content

Commit

Permalink
Map Dispatch to Props
Browse files Browse the repository at this point in the history
  • Loading branch information
15Dkatz committed Oct 23, 2022
1 parent 08f2c8a commit 48f66eb
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions evens-or-odds/src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@ import { connect } from 'react-redux';
import { startGame, cancelGame } from '../actions/settings';

class App extends Component {
startGame = () => {
this.props.dispatch(startGame())
}

cancelGame = () => {
this.props.dispatch(cancelGame())
}

render() {
console.log('this', this);

Expand All @@ -22,13 +14,13 @@ class App extends Component {
<div>
<h3>The game is on!</h3>
<br />
<button onClick={this.cancelGame}>Cancel Game</button>
<button onClick={this.props.cancelGame}>Cancel Game</button>
</div>
) : (
<div>
<h3>A new game awaits</h3>
<br />
<button onClick={this.startGame}>Start Game</button>
<button onClick={this.props.startGame}>Start Game</button>
</div>
)
}
Expand All @@ -43,6 +35,13 @@ const mapStateToProps = state => {
return { gameStarted: state.gameStarted };
}

const componentConnector = connect(mapStateToProps);
const mapDispatchToProps = dispatch => {
return {
startGame: () => dispatch(startGame()),
cancelGame: () => dispatch(cancelGame()),
};
}

const componentConnector = connect(mapStateToProps, mapDispatchToProps);

export default componentConnector(App);

0 comments on commit 48f66eb

Please sign in to comment.