mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
b90c77b17f
* 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
41 lines
867 B
JavaScript
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)
|