Last active
December 23, 2015 20:56
-
-
Save gabrielhpugliese/3c3bf1fd42153ae24440 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component } from 'react'; | |
import { bindActionCreators } from 'redux'; | |
import { connect } from 'react-redux'; | |
import * as CounterActions from '../actions/counter'; | |
const counterProps = ({ counter }) => ({ counter }); | |
const dispatchToActionCreators = dispatch => bindActionCreators(CounterActions, dispatch); | |
@connect(counterProps, dispatchToActionCreators) | |
class Counter extends Component { | |
render () { | |
const { counter, increment, decrement } = this.props; | |
return ( | |
<div> | |
<h1>Counter: {counter}</h1> | |
<button onClick={() => increment()}>+</button> | |
<button onClick={() => decrement()}>-</button> | |
</div> | |
); | |
} | |
} | |
export default Counter; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use the fact that second arg to
connect()
can just be an object to make it even shorter: