小编Ign*_*cio的帖子

Nextjs切换body背景颜色

我正在尝试制作一个按钮来更改 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)

reactjs next.js

1
推荐指数
1
解决办法
3万
查看次数

标签 统计

next.js ×1

reactjs ×1