use*_*527 3 reactjs material-ui
我在 App.js 中创建了一个主题,它覆盖了主要和次要颜色。我有 ThemeProvider 包装了一个 Home 组件。覆盖的值未显示在 Home 组件中。我究竟做错了什么?
应用程序.js
import React from 'react'
import { ThemeProvider, createMuiTheme } from '@material-ui/core/styles'
import purple from '@material-ui/core/colors/purple'
import green from '@material-ui/core/colors/green'
import Home from './components/Home'
const theme = createMuiTheme({
overrides: {
pallete: {
primary: {
main: purple[500]
},
secondary: {
main: green[500]
}
}
}
})
const App = () => {
return (
<ThemeProvider theme={theme}>
<Home />
</ThemeProvider>
)
}
export default App
Run Code Online (Sandbox Code Playgroud)
主页.js
import React from 'react'
import { useTheme } from '@material-ui/core/styles'
import { Container, Grid, AppBar, Toolbar, CssBaseline } from '@material-ui/core'
const Home = () => {
const theme = useTheme()
return (
<Container max="lg">
<CssBaseline />
<Grid container>
<Grid item xs={12}>
<AppBar color="primary">
<Toolbar>
Hello World
</Toolbar>
</AppBar>
</Grid>
</Grid >
</Container >
)
}
export default Home
I would think that in my AppBar the color="primary" should show up with the overridden primary color. But it's not happening.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2617 次 |
| 最近记录: |