rsnext/examples/with-redux-observable/pages/index.js
Todor Totev 34f82a996b
Refactor with redux observable (#13615)
Related to [11014](https://github.com/vercel/next.js/issues/11014)

1. Moved the reducer into the store and created new store file
2. The example was using a server that was no longer available, now it uses JSON placeholder instead.
3. Moved from getInitialProps to getStaticProps
4. Refactored all the classes to functional components, using the new redux hooks API.
5. Upgraded all the packages and using custom redux wrapper instead of next-redux-wrapper, which I have removed from the example.
6. Upgraded all the other packages.

Please, let me know if I should change anything.
2020-06-03 09:23:16 +00:00

30 lines
644 B
JavaScript

import { useEffect } from 'react'
import { useDispatch } from 'react-redux'
import Link from 'next/link'
import UserInfo from '../components/UserInfo'
import { stopFetchingUsers, startFetchingUsers } from '../store/actions'
const Counter = () => {
const dispatch = useDispatch()
useEffect(() => {
dispatch(startFetchingUsers())
return () => {
dispatch(stopFetchingUsers())
}
}, [dispatch])
return (
<div>
<h1>Index Page</h1>
<UserInfo />
<br />
<nav>
<Link href="/other">
<a>Navigate to "/other"</a>
</Link>
</nav>
</div>
)
}
export default Counter