├── .gitignore
├── .npmrc
├── README.md
├── components
├── IncrementCounter.js
├── Page.js
└── Users.js
├── package.json
├── pages
├── _app.js
├── index.js
└── other.js
├── redux.md
└── store
├── counter
├── action.js
└── reducer.js
├── store.js
└── users
├── action.js
└── reducer.js
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # next.js
12 | /.next/
13 | /out/
14 |
15 | # production
16 | /build
17 |
18 | # misc
19 | .DS_Store
20 | *.pem
21 |
22 | # debug
23 | npm-debug.log*
24 | yarn-debug.log*
25 | yarn-error.log*
26 |
27 | # local env files
28 | .env.local
29 | .env.development.local
30 | .env.test.local
31 | .env.production.local
32 |
33 | # vercel
34 | .vercel
35 |
--------------------------------------------------------------------------------
/.npmrc:
--------------------------------------------------------------------------------
1 | package-lock=false
2 | save-exact=true
3 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # With Redux Wrapper Example
3 |
4 | Usually splitting your app state into `pages` feels natural but sometimes you'll want to have global state for your app.
5 | The concept of global state caters to both client side and server side stores with the help of a master reducer.
6 | This is an example on how you can use redux that also works with our universal rendering approach. This is just a way you
7 | can do it but it's not the only one. Please find other methods under the official documentation of next-redux-wrapper.
8 | Docs: https://github.com/kirill-konshin/next-redux-wrapper
9 |
10 | ## How to use
11 |
12 | Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example:
13 |
14 | ```bash
15 | git clone https://github.com/mayank7924/nextjs-with-redux
16 | cd nextjs-with-redux
17 | npm install
18 | for running development server: npm run dev
19 | for running prod like server: npm run build, npm run start
20 | ```
21 |
22 | Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).
23 |
24 | ## NOTE: There are three projects present in this repo in separate branches
25 | main: redux with Next.JS
26 | |-starter-project: starter Next.JS app
27 | |-redux-toolkit: redux-toolkit wuth Next.JS
28 |
29 |
30 |
--------------------------------------------------------------------------------
/components/IncrementCounter.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { useSelector, useDispatch } from 'react-redux'
3 |
4 | const IncrementCounter = () => {
5 | const dispatch = useDispatch()
6 | const counter = useSelector((state) => state.counter.count)
7 | return (
8 |