Next.js Discord

Discord Forum

Need help with adding dark mode

Answered
Cape lion posted this in #help-forum
Open in Discord
Cape lionOP
i am using next-themes
and i put everything inside providers tag and used ThemeProvider for adding it but i am getting this error

Error: (0 , reactWEBPACK_IMPORTED_MODULE_0.createContext) is not a function
Answered by joulev
remove the dash
View full answer

15 Replies

Chinese Egret
Not used that library, why not using plain CSS variables?
please add a reproduction repository. i'm using next-themes and it works completely fine
Cape lionOP
import { Inter } from 'next/font/google'
import './globals.css'
import Header from '@/components/Header'
import Providers from './Providers'


export default function RootLayout({ children }) {             // layout.js


  return (
    <html lang="en">
    <body>
      <Providers>
    
        <Header />

    

        {children}
      </Providers>
    </body>
  </html>
  )
}
"use-client";
import { ThemeProvider } from 'next-themes'
import React from 'react'

export default function Providers({children}) {         //Providers.js
  return (
    <div>
    <ThemeProvider>
        {children}
    </ThemeProvider>
    </div>
  )
}
@joulev should i send anything else too ?
@Cape lion <@484037068239142956> should i send anything else too ?
could you try to make a minimal github repo?
your code above looks ok
WAIT NVM
you are using "use-client"; which is wrong
remove the dash
Answer
"use client"
Cape lionOP
wow thank you
it worked :))
glad it helped!
have a nice day