0

My redux toolkit is not working in my nextjs 13 e-commerce app. I also using the technique to wrap the app with custom 'use-client' provider to provide store. But app is crashing and giving error here is the screen shot is attached Screen shot of error

Here my code currently I am using

Layout.jsx

import { Providers } from "./Providers";
import Navbar from "./components/Navbar";
import "./globals.css";

export const metadata = {
    title: "Prime Clothing | Purchase on discounted prices",
    description: "Prime Clothing | Purchase on discounted prices",
};
export default function RootLayout({ children }) {
    return (
        <html lang="en">
            <body>
                <Providers>
                    <Navbar />
                    <main className="container mt-24">{children}</main>
                </Providers>
            </body>
        </html>
    );
}

store.js

import { configureStore } from "@reduxjs/toolkit";
import cartSlice from "./cart/cartSlice";
export const store = configureStore({
    reducer: {
        cart: cartSlice,
    },
});

Providers.jsx

"use client";
import { Provider } from "react-redux";
import { store } from "@/app/redux-store/store";
export function Providers({ children }) {
    return <Provider store={store}>{children}</Provider>;
}

cartSlice.js

import { createSlice } from "@reduxjs/toolkit";
const initialState = {
    cart: [],
};
export const cartSlice = createSlice({
    name: "cart",
    initialState,
    reducers: {
        addToCart: (state, action) => {
            const item = action.payload;
        },
    },
});
export const { addToCart } = cartSlice.actions;
export default cartSlice.reducer;
  • What’s your Next.js version ? – Youssouf Oumar Apr 22 '23 at 11:19
  • next js version 13.3.0 and react version 18.2.0 – aamir rashid Apr 22 '23 at 12:01
  • The server components isn’t ready/easy option to use. The ssg/ssr hydrations are really advanced topic. If you want to play that game with redux, next-redux-wrapper prolly the best place to start, without it running store on server-sides isn’t really an option… – antokhio Apr 24 '23 at 22:08

0 Answers0