2018-05-10 17:40:21 +00:00
|
|
|
import React from 'react'
|
|
|
|
import { bindActionCreators } from 'redux'
|
|
|
|
import { startClock, addCount, serverRenderClock } from '../store'
|
|
|
|
import Page from '../components/Page'
|
|
|
|
import { connect } from 'react-redux'
|
|
|
|
|
|
|
|
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 () {
|
2018-12-17 16:34:32 +00:00
|
|
|
return <Page title='Other Page' linkTo='/' />
|
2018-05-10 17:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-17 16:34:32 +00:00
|
|
|
const mapDispatchToProps = dispatch => {
|
2018-05-10 17:40:21 +00:00
|
|
|
return {
|
|
|
|
addCount: bindActionCreators(addCount, dispatch),
|
|
|
|
startClock: bindActionCreators(startClock, dispatch)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-17 16:34:32 +00:00
|
|
|
export default connect(
|
|
|
|
null,
|
|
|
|
mapDispatchToProps
|
|
|
|
)(Counter)
|