mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
3db3f4b42a
It's better that Counter behave not only `increment (add)` but also `decrement` or `reset`. * Add decrement, reset handlers and rename add handler in `components/counter.js` * Add increment, decrement, reset actions to `store.js` * Rename page component class name: Counter => Index in `pages/index.js` * Remove needless dispatch count event on getInitialProps in `pages/index.js` * Format JSX to be readable in `pages/_app.js` * Remove needless line from `components/examples.js` * Remove needless spaces in `lib/with-redux-store.js`
31 lines
607 B
JavaScript
31 lines
607 B
JavaScript
import React from 'react'
|
|
import {connect} from 'react-redux'
|
|
import {startClock, serverRenderClock} from '../store'
|
|
import Examples from '../components/examples'
|
|
|
|
class Index extends React.Component {
|
|
static getInitialProps ({ reduxStore, req }) {
|
|
const isServer = !!req
|
|
reduxStore.dispatch(serverRenderClock(isServer))
|
|
|
|
return {}
|
|
}
|
|
|
|
componentDidMount () {
|
|
const {dispatch} = this.props
|
|
this.timer = startClock(dispatch)
|
|
}
|
|
|
|
componentWillUnmount () {
|
|
clearInterval(this.timer)
|
|
}
|
|
|
|
render () {
|
|
return (
|
|
<Examples />
|
|
)
|
|
}
|
|
}
|
|
|
|
export default connect()(Index)
|