1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/examples/with-redux-saga/components/counter.js

41 lines
867 B
JavaScript
Raw Normal View History

import React, {Component} from 'react'
import {connect} from 'react-redux'
import {increment, decrement, reset} from '../actions'
class Counter extends Component {
increment = () => {
this.props.dispatch(increment())
}
decrement = () => {
this.props.dispatch(decrement())
}
reset = () => {
this.props.dispatch(reset())
}
render () {
const {count} = this.props
return (
<div>
<style jsx>{`
div {
padding: 0 0 20px 0;
}
`}</style>
<h1>
Count: <span>{count}</span>
</h1>
<button onClick={this.increment}>+1</button>
<button onClick={this.decrement}>-1</button>
<button onClick={this.reset}>Reset</button>
</div>
)
}
}
const mapStateToProps = ({count}) => ({count})
export default connect(mapStateToProps)(Counter)