mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
ba54c6ac3d
Use the original idea of provider wrapper from #1193 and remove unnecessary `initStore` in every page.
28 lines
685 B
JavaScript
28 lines
685 B
JavaScript
import React from 'react'
|
|
import { nextConnect, reducer, startClock, setPageTitle } from '../store'
|
|
import Page from '../components/Page'
|
|
|
|
class Counter extends React.Component {
|
|
static getInitialProps ({ store, isServer }) {
|
|
store.dispatch({ type: 'TICK', light: !isServer, ts: Date.now() })
|
|
store.dispatch({ type: 'SET_PAGE_TITLE', title: 'Other Page' })
|
|
return { isServer }
|
|
}
|
|
|
|
componentDidMount () {
|
|
this.timer = this.props.dispatch(startClock())
|
|
}
|
|
|
|
componentWillUnmount () {
|
|
clearInterval(this.timer)
|
|
}
|
|
|
|
render () {
|
|
return (
|
|
<Page title={this.props.title} linkTo='/' />
|
|
)
|
|
}
|
|
}
|
|
|
|
export default nextConnect((state) => state)(Counter)
|