rsnext/examples/with-redux-wrapper/pages/index.js
Thang Vu 530a2a397d
upgrade next-redux-wrapper to 7.0.2 (#26521)
## Bug

- [x] Related issues linked using `fixes #number`: Fixes #26338
- [ ] Integration tests added
2021-07-16 12:28:31 +00:00

33 lines
897 B
JavaScript

import { useEffect } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import Page from '../components/Page'
import { addCount } from '../store/count/action'
import { wrapper } from '../store/store'
import { serverRenderClock, startClock } from '../store/tick/action'
const Index = (props) => {
useEffect(() => {
const timer = props.startClock()
return () => {
clearInterval(timer)
}
}, [props])
return <Page title="Index Page" linkTo="/other" />
}
export const getStaticProps = wrapper.getStaticProps((store) => () => {
store.dispatch(serverRenderClock(true))
store.dispatch(addCount())
})
const mapDispatchToProps = (dispatch) => {
return {
addCount: bindActionCreators(addCount, dispatch),
startClock: bindActionCreators(startClock, dispatch),
}
}
export default connect(null, mapDispatchToProps)(Index)