mirror of
https://github.com/zhigang1992/react.git
synced 2026-02-09 22:50:06 +08:00
Merge pull request #41 from nocategory/update-docs
docs: fix switch themes code
This commit is contained in:
@@ -28,21 +28,20 @@ export const meta = {
|
||||
3. Update the value of `theme.type`, and the theme of all components will follow automatically.
|
||||
|
||||
```jsx
|
||||
import { CSSBaseline, ZEITUIProvider, useTheme } from '@zeit-ui/react'
|
||||
import { CSSBaseline, ZEITUIProvider } from '@zeit-ui/react'
|
||||
|
||||
const [type, setType] = useState('light')
|
||||
const currentTheme = useTheme()
|
||||
const switchThemes = () => () => {
|
||||
const nextTheme = currentTheme.type === 'dark' ? 'light' : 'dark'
|
||||
setType(nextTheme)
|
||||
const App = () => {
|
||||
const [themeType, setThemeType] = useState('dark')
|
||||
const switchThemes = () => {
|
||||
setThemeType(lastThemeType => lastThemeType === 'dark' ? 'light' : 'dark')
|
||||
}
|
||||
return (
|
||||
<ZEITUIProvider theme={{ type: themeType }}>
|
||||
<CSSBaseline />
|
||||
<YourComponent onClick={switchThemes} />
|
||||
</ZEITUIProvider>
|
||||
)
|
||||
}
|
||||
|
||||
const App = () => (
|
||||
<ZEITUIProvider theme={{ type }}>
|
||||
<CSSBaseline />
|
||||
<YourAppComponent onClick={switchThemes}/>
|
||||
</ZEITUIProvider>
|
||||
)
|
||||
```
|
||||
|
||||
<Spacer y={3} />
|
||||
|
||||
Reference in New Issue
Block a user