2016-12-22 05:10:54 +00:00
|
|
|
import React from 'react'
|
2018-05-07 13:03:54 +00:00
|
|
|
import {connect} from 'react-redux'
|
|
|
|
import {startClock, addCount, serverRenderClock} from '../store'
|
|
|
|
import Examples from '../components/examples'
|
2016-12-22 05:10:54 +00:00
|
|
|
|
2017-02-18 04:10:27 +00:00
|
|
|
class Counter extends React.Component {
|
2018-05-07 13:03:54 +00:00
|
|
|
static getInitialProps ({ reduxStore, req }) {
|
|
|
|
const isServer = !!req
|
|
|
|
reduxStore.dispatch(serverRenderClock(isServer))
|
|
|
|
reduxStore.dispatch(addCount())
|
2017-04-30 20:44:24 +00:00
|
|
|
|
2018-05-07 13:03:54 +00:00
|
|
|
return {}
|
2016-12-22 05:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount () {
|
2018-05-07 13:03:54 +00:00
|
|
|
const {dispatch} = this.props
|
|
|
|
this.timer = startClock(dispatch)
|
2016-12-22 05:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount () {
|
|
|
|
clearInterval(this.timer)
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
return (
|
2018-05-07 13:03:54 +00:00
|
|
|
<Examples />
|
2016-12-22 05:10:54 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2017-02-18 04:10:27 +00:00
|
|
|
|
2018-05-07 13:03:54 +00:00
|
|
|
export default connect()(Counter)
|