The code you’ve shared is already in the correct “modern” shape for a Client Component theme provider in the App Router: a use client wrapper that accepts children and is rendered from a Server Component layout, which matches the current pattern shown in the docs for context providers.Context providers
In other words, structurally you don’t need to change this for newer Next.js:
"use client";
import { type ComponentProps } from "react";
import { ThemeProvider as NextThemesProvider } from "next-themes";
type ThemeProviderProps = ComponentProps<typeof NextThemesProvider>;
export function ThemeProvider({ children, ...props }: ThemeProviderProps) {
return (
<NextThemesProvider
storageKey="theme-preference"
attribute="class"
defaultTheme="system"
enableSystem
disableTransitionOnChange
{...props}
>
{children}
</NextThemesProvider>
);
}
The main version-related issue mentioned in the templates is that next-themes is not yet updated for React 19, so when you install dependencies for a Next.js 15 template you must use npm i --legacy-peer-deps to avoid peer‑dependency conflicts.Wisp blog template
So to “make it up to date” for the latest Next.js:
-
Keep this provider as a Client Component and use it from your app/layout.tsx, similar to:
import ThemeProvider from "./theme-provider";
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html>
<body>
<ThemeProvider>{children}</ThemeProvider>
</body>
</html>
);
}