2016-12-22 05:10:54 +00:00
|
|
|
import React from 'react'
|
2017-04-30 20:44:24 +00:00
|
|
|
import { bindActionCreators } from 'redux'
|
|
|
|
import { initStore, startClock, addCount, serverRenderClock } from '../store'
|
2018-03-06 12:34:28 +00:00
|
|
|
import withRedux from '../utils/withRedux'
|
2017-01-08 15:04:35 +00:00
|
|
|
import Page from '../components/Page'
|
2016-12-22 05:10:54 +00:00
|
|
|
|
2017-02-18 04:10:27 +00:00
|
|
|
class Counter extends React.Component {
|
|
|
|
static getInitialProps ({ store, isServer }) {
|
2017-04-30 20:44:24 +00:00
|
|
|
store.dispatch(serverRenderClock(isServer))
|
|
|
|
store.dispatch(addCount())
|
|
|
|
|
2017-02-18 04:10:27 +00:00
|
|
|
return { isServer }
|
2016-12-22 05:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount () {
|
2017-04-30 20:44:24 +00:00
|
|
|
this.timer = this.props.startClock()
|
2016-12-22 05:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount () {
|
|
|
|
clearInterval(this.timer)
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
return (
|
2017-02-18 17:11:54 +00:00
|
|
|
<Page title='Index Page' linkTo='/other' />
|
2016-12-22 05:10:54 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2017-02-18 04:10:27 +00:00
|
|
|
|
2017-04-30 20:44:24 +00:00
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
|
|
return {
|
|
|
|
addCount: bindActionCreators(addCount, dispatch),
|
|
|
|
startClock: bindActionCreators(startClock, dispatch)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default withRedux(initStore, null, mapDispatchToProps)(Counter)
|