Skip to content

Next.js 13: SWRConfig should mark components as "use client" #2292

Answered by SukkaW
itta611 asked this question in Ideas
Discussion options

You must be logged in to vote

The current workaround would be manually wrapping <SWRConfig /> in your client components:

// my-provider.client.tsx
'use client';
export const MyProvider = ({ children }: React.PropWithChildren<unknown>) => {
  return <SWRConfig>{children}</SWRConfig>
};

// layout.tsx
export default function Layout({ children }: React.PropWithChildren<unknown>) {
  return <MyProvider>{children}</MyProvider>
}

And IMHO <SWRConfig /> should also include import 'client-only'.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by promer94
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2253 on December 15, 2022 15:54.