TypeError: (0 , _react.createContext) is not a function on Nextjs using Redux #49074
-
SummaryI'm working on a NextJS 13 project which uses redux. I used store.ts: import { configureStore } from "@reduxjs/toolkit"; export const store = configureStore({ export type RootState = ReturnType; provider.tsx: import { store } from "./store"; export function Providers({ children }: { children: React.ReactNode }) { |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 12 replies
-
Got a repository/code example to look at? Most likely You are using appDir and have not properly used the Redux Provider. The Provider has to be used within a component marked as Basically, one file where it is just these contents, for example 'use client';
import { ThemeProvider } from 'acme-theme'; // This should be the Redux provider
export function Providers({ children }) {
return (
<ThemeProvider>
{children}
</ThemeProvider>
);
} And then at your top layout: import { Providers } from './components/providers';
export default function RootLayout({ children }) {
return (
<html>
<body>
<Providers>{children}</Providers>
</body>
</html>
);
} |
Beta Was this translation helpful? Give feedback.
-
import Image from 'next/image' function Content() {
} export default Content; im facing the same error except im not using any hooks for interactivity and as soon as i try to import the {useTranslation} from the i18next i get that error but when i do the "use client" it works just fine |
Beta Was this translation helpful? Give feedback.
Right, this is a server component, using
async/await
, and at the same time is trying to use a client side hook, such asuseDispatch
- to lay interactivity. That ain't gonna fly.Please refer to, https://beta.nextjs.org/docs/rendering/server-and-client-components#when-to-use-server-vs-client-components:
So it is not only that
dispatch
won't work, but also the onClick won't work: