Skip to content

Is there a way to access useTheme hook in _app.js #490

Answered by promer94
junaid33 asked this question in Q&A
Discussion options

You must be logged in to vote

First you need to install the latest version of next-themes and nextra

"dependencies": {
    "next-themes": "0.2.0-beta.2",
    "nextra-theme-docs": "2.0.0-alpha.54",
    "nextra": "2.0.0-alpha.54"
    ....
  }

Then you should ba able to access the theme in _app.js

import 'nextra-theme-docs/style.css'
import { useTheme } from 'next-themes'
import React from 'react'

const TestTheme = ({ children }) => {
  const { theme, setTheme, systemTheme } = useTheme()
  console.log('theme', theme, systemTheme)
  return children
}

export default function MyApp({ Component, pageProps }) {
  // Use the layout defined at the page level, if available
  const getLayout = Component.getLayout || (page => page)

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@junaid33
Comment options

@evanxshu
Comment options

@TheMikeyRoss
Comment options

@arno-fukuda
Comment options

@JanBrin
Comment options

Answer selected by junaid33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
6 participants