Skip to content

Instantly share code, notes, and snippets.

@barraponto
Created October 11, 2018 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barraponto/c02871714a87f796b3bc93683032577e to your computer and use it in GitHub Desktop.
Save barraponto/c02871714a87f796b3bc93683032577e to your computer and use it in GitHub Desktop.
import { connect } from 'react-redux';
const Score = ({ score }) => (<div className="game-score"> {score} </div>);
const mapStateToProps = (state) => ({ score: state.game.score });
export default connect(mapStateToProps)(Score)
/*******************************/
import { connect } from 'react-redux';
const shoot = () => ({type: 'SHOOT', weapon: 'laser'});
const ShootButton = ({ shoot }) => (
<button className="game-controls-fire" onClick={ shoot }>
Fire
</button>
);
const mapStateToProps = () => ({});
const mapDispatchToProps = (dispatch) => ({ shoot: (e) => dispatch(shoot()) });
export default connect(mapStateToProps, mapDispatchToProps)(ShootButton)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment