Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up Redux toolkit with Next js 14.0.1

Been running into a couple of issues trying to setup reduxt toolkit in next 14 as see n below. i've followed the exact steps on several youtube videos and articles online. but stil getting stuck here as i can't wrap my head around what seems to be the issue enter image description here

when it get's compiled by next on the frontend i get this error enter image description here

and this is the store.ts file enter image description here

like image 482
chowacross Avatar asked Oct 18 '25 01:10

chowacross


1 Answers

In next.js, you have to créate a providers file, and import it for using in layout. Something like this:

// Providers.js
    'use client';
import { Provider } from "react-redux";
import { store } from "./store";
import { Providers } from "@/Redux/provider"

export function Providers({ children }) {
  return <Provider store={store}>{children}</Provider>;
}

Now in your layout.js, import and use it:

 import { Inter } from "next/font/google";
import "./globals.css";
import { Providers } from "@/Redux/provider"


const inter = Inter({ subsets: ["latin"] });

export const metadata = {
  title: "Your App",
  description: "This is a example for use redux in next.js versión 13 >=",
};

export default function RootLayout({ children }) {
  return (
    <Providers store={store}>
      <html lang="en">
        <body className={inter.className}>
          <Header />
          {children}
        </body>
      </html>
    </Providers>
  );
}

In the example, I créate a folder Redux for settings and files.

I hope to help you. =)

like image 60
Richard Reyes Avatar answered Oct 20 '25 16:10

Richard Reyes