Using Redux Toolkit With Next.js App
Integrating Redux Toolkit with Next.js app. Use `useAppDispatch` and `useAppSelector` hooks from `redux/hooks.js`. Create store instance in `store.js` and wrap app with `StoreProvider` component.
A straight forward example of using Redux Tool Kit with Nextjs app.
redux/hooks.js
import { useDispatch, useSelector, useStore } from "react-redux";
// Use throughout the app instead of plain `useDispatch` and `useSelector`
export const useAppDispatch = useDispatch.withTypes();
export const useAppSelector = useSelector.withTypes();
export const useAppStore = useStore.withTypes();
redux/store.js
import { configureStore } from "@reduxjs/toolkit";
import userReducer from "../features/user/userSlice";
export const makeStore = () => {
return configureStore({
reduce...