- 我正在使用@smakosh的 GatsbyJS 主题和Theme UI插件;
- 我
useColorMode
从Hooks 中学会了使用Hooks -useThemeUI
和useColorMode
; - 我的整个代码是完全正确的;
- 我已经清除了 GatsbyJS、npm 和浏览器的缓存,但同样的错误仍然存在;
- 你可以拿我的小包来分析:https ://drive.google.com/file/d/1SsgPXAq9zMv8Yp4XDjy3MJLeWun-J3UQ/view?usp=sharing 。
编译后,我收到两个错误:
TypeError: setMode is not a function
;InvalidCharacterError: String contains an invalid character
:
检查我的整个代码:
/** @jsx jsx */
import { jsx, Styled, useColorMode } from 'theme-ui'
import { Context } from '../../common'
import SelectLanguage from './SelectLanguage'
import { Navegador, Input, Label, Submenu, StyledHeader } from './styles'
function Header()
{
const themes = ['deep', 'funk', 'future', 'swiss'];
const modes = ['default', 'dark'];
const [mode, setMode, setTheme, theme] = useColorMode()
return (
<Styled.root>
<Context.Consumer>
{({ toggleLanguage, lang }) => (
<StyledHeader>
<Navegador id="menu">
<li>
<SelectLanguage lang={lang} toggleLanguage={toggleLanguage} />
</li>
<li>
<Input id="modes" type="checkbox" name="menu"/>
<Label for="modes">Modes</Label>
<Submenu className="submenu">
<li onClick={e => setMode("default")}> Light </li>
<li onClick={e => setMode("dark")}> Dark </li>
</Submenu>
</li>
<li>
<Input id="themes" type="checkbox" name="menu"/>
<Label for="themes">Themes</Label>
<Submenu className="submenu">
<li onClick={e => setTheme("deep")}> Deep </li>
<li onClick={e => setTheme("funk")}> Funk </li>
<li onClick={e => setTheme("future")}> Futuristic </li>
<li onClick={e => setTheme("swiss")}> Swiss </li>
</Submenu>
</li>
</Navegador>
</StyledHeader>
)}
</Context.Consumer>
</Styled.root>
)
}
export default Header