rsnext/examples/with-redux-thunk/actions.js
TodorTotev f3ea363df7
Refactor with redux thunk example (#13336)
Related to [11014](https://github.com/zeit/next.js/issues/11014)

1. I have changed the component from class to functional.
2. I have removed the getInitialProps and used getStaticProps instead.
3. I have removed the redundant connect to redux @ the index page, due to the fact that now we can dispatch the action with the required hook.

If you want me to change anything or you are not satisfied with any given change, I'm open to suggestions.
2020-05-25 16:55:33 +00:00

23 lines
649 B
JavaScript

import * as types from './types'
// INITIALIZES CLOCK ON SERVER
export const serverRenderClock = () => (dispatch) =>
dispatch({
type: types.TICK,
payload: { light: false, ts: Date.now() },
})
// INITIALIZES CLOCK ON CLIENT
export const startClock = () => (dispatch) =>
setInterval(() => {
dispatch({ type: types.TICK, payload: { light: true, ts: Date.now() } })
}, 1000)
// INCREMENT COUNTER BY 1
export const incrementCount = () => ({ type: types.INCREMENT })
// DECREMENT COUNTER BY 1
export const decrementCount = () => ({ type: types.DECREMENT })
// RESET COUNTER
export const resetCount = () => ({ type: types.RESET })