2018-03-06 12:34:28 +00:00
|
|
|
import React from 'react'
|
|
|
|
import { bindActionCreators } from 'redux'
|
2018-05-08 12:57:41 +00:00
|
|
|
import { startClock, addCount, serverRenderClock } from '../store'
|
|
|
|
import { connect } from 'react-redux'
|
2018-03-06 12:34:28 +00:00
|
|
|
import Page from '../components/Page'
|
|
|
|
|
|
|
|
class Counter extends React.Component {
|
|
|
|
static getInitialProps ({ store, isServer }) {
|
|
|
|
store.dispatch(serverRenderClock(isServer))
|
|
|
|
store.dispatch(addCount())
|
|
|
|
|
|
|
|
return { isServer }
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount () {
|
|
|
|
this.timer = this.props.startClock()
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount () {
|
|
|
|
clearInterval(this.timer)
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
return (
|
|
|
|
<Page title='Index Page' linkTo='/other' />
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
|
|
return {
|
|
|
|
addCount: bindActionCreators(addCount, dispatch),
|
|
|
|
startClock: bindActionCreators(startClock, dispatch)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-08 12:57:41 +00:00
|
|
|
export default connect(null, mapDispatchToProps)(Counter)
|