admin管理员组文章数量:1279188
I'm using MUI with Next.js. My project needs support for both dark and light themes with a custom color palette.
To switch themes, I use useColorScheme
from MUI. Here’s how I set the theme:
const lightPalette = ...
const darkPalette = ...
const getPalette = (mode: 'light' | 'dark' | 'system') => ({
mode,
...(mode === 'light'? lightPalette : darkPalette),
})
And to apply the theme,
import { useColorScheme } from '@mui/material/styles';
...
const [mode, setMode] = useColorScheme()
const theme = createTheme({
colorSchemes: { light: true, dark: true },
...getPalette(mode),
})
...
<ThemeProvider theme={theme} >
...
</ThemeProvider>
The type of mode is 'light', 'dark', or 'system'. When the mode is set to 'system', how do I determine which mode the system is using? Is this the correct way to implement theme switching with Next.js and MUI?
本文标签: nextjsWhat is the proper way of using useColorScheme of MUIStack Overflow
版权声明:本文标题:next.js - What is the proper way of using useColorScheme of MUI? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741279505a2369924.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论