Next.js Discord

Discord Forum

When I try to use RDK query in page component (server) it gives error

Unanswered
Lionhead posted this in #help-forum
Open in Discord
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

@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 />;
}
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