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
yhirano55 b90c77b17f Improve with-redux-saga example (#4392)
* Rename page component's class name: Counter => Index, Counter => Other
* Rename counter component class name: AddCount => Counter
* Add counter actions `decrement` and `reset` same as with-redux example
* Modify page link by NavigateTo attr in Page component
* Modify license MIT => ISC same as others in package.json
* Modify README
2018-05-16 10:47:12 +02:00

41 lines
867 B
JavaScript

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)