rsnext/examples/with-redux-persist/components/counter.js
TodorTotev 5a5e6004d7
Refactor with redux persist example (#13338)
Related to [11014](https://github.com/zeit/next.js/issues/11014)

First and most important, removed the getInitialProps and used getStaticProps.

Then, I refactored Counter, DataList and Examples components.
I have refactored them from class-based components to functional. Also in each component the redux implementation was refactored using the new hooks API, which resulted in ~40% less code.

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

20 lines
567 B
JavaScript

import { useSelector, useDispatch } from 'react-redux'
import { incrementCount, decrementCount, resetCount } from '../store'
const Counter = () => {
const counter = useSelector((state) => state.count)
const dispatch = useDispatch()
return (
<div>
<h1>
Count: <span>{counter}</span>
</h1>
<button onClick={() => dispatch(incrementCount())}>+1</button>
<button onClick={() => dispatch(decrementCount())}>-1</button>
<button onClick={() => dispatch(resetCount())}>Reset</button>
</div>
)
}
export default Counter