rsnext/examples/with-redux-saga/pages/index.js

30 lines
720 B
JavaScript
Raw Normal View History

import { useEffect } from 'react'
import { useDispatch } from 'react-redux'
import { END } from 'redux-saga'
import { wrapper } from '../store'
import { loadData, startClock, tickClock } from '../actions'
2017-07-13 20:55:29 +02:00
import Page from '../components/page'
const Index = () => {
const dispatch = useDispatch()
useEffect(() => {
dispatch(startClock())
}, [dispatch])
return <Page title="Index Page" linkTo="/other" NavigateTo="Other Page" />
}
2017-07-13 20:55:29 +02:00
export const getStaticProps = wrapper.getStaticProps(async ({ store }) => {
store.dispatch(tickClock(false))
2017-07-13 20:55:29 +02:00
if (!store.getState().placeholderData) {
store.dispatch(loadData())
store.dispatch(END)
2017-07-13 20:55:29 +02:00
}
await store.sagaTask.toPromise()
})
2017-07-13 20:55:29 +02:00
export default Index