When I try to use RDK query in page component (server) it gives error
Unanswered
Lionhead posted this in #help-forum
LionheadOP
I have started working on Next.js and Next 13. When I try to use Redux Toolkit query in the page.tsx file (server), I get the error 'TypeError: (0, _react.createContext) is not a function,' and I haven't been able to figure out the reason for this. What am I doing wrong?
8 Replies
@Lionhead I have started working on Next.js and Next 13. When I try to use Redux Toolkit query in the page.tsx file (server), I get the error 'TypeError: (0, _react.createContext) is not a function,' and I haven't been able to figure out the reason for this. What am I doing wrong?
redux toolkit requires client components
same for any state management system
@joulev redux toolkit requires client components
LionheadOP
So how can I get data from api with SSR?
@Lionhead So how can I get data from api with SSR?
hmm something like this?
import PageClient from "./page-client";
export default async function Page() {
const data = await getData();
return <PageClient data={data} />;
}"use client";
export default function PageClient({ data }) {
// use redux and everything client-side here
return <div />;
}@joulev hmm something like this?
ts
import PageClient from "./page-client";
export default async function Page() {
const data = await getData();
return <PageClient data={data} />;
}
ts
"use client";
export default function PageClient({ data }) {
// use redux and everything client-side here
return <div />;
}
LionheadOP
Oh I got it thanks so much
but I can't use redux toolkit query in ssr right?
as i said, anything that is related to client-side states must be in client components
you can however fetch the initial data in server components and pass it to the client components and initialise the store using that data