我正在尝试制作一个按钮来更改 Nextjs 中的背景。为什么这不起作用?
_app.js
import '../styles/global.css'
import { AppProps } from 'next/app'
import { useState } from 'react'
export default function App({ Component, pageProps }: AppProps) {
const [isDark, setIsDark] = useState(false)
return (
<>
<Component {...pageProps} />
<style jsx global>{`
${ isDark ? 'body {background: darkslategray;}' : 'body {background: antiquewhite;}' }
`}</style>
</>
)
}
Run Code Online (Sandbox Code Playgroud)