Rup*_*ind 7 emotion typescript reactjs material-ui styled-components
我正在使用@emotion/react
主题并将主题注入其中,我可以使用useTheme
组件访问主题,但无法使用@emotion/styled
. 有什么帮助吗?
//libs
import React from 'react';
import styled from '@emotion/styled';
import StylesProvider from '@mui/styles/StylesProvider';
import { ThemeProvider } from '@emotion/react';
const THEME = {
primary: 'red'
}
const StyledText = styled('p')`
color: ${({ theme }) => theme.primary};
`;
function App() {
return (
<StylesProvider injectFirst>
<ThemeProvider theme={THEME}>
<StyledText>test</StyledText>
</ThemeProvider>
</StylesProvider>
);
}
export default App;
here is sample code
Run Code Online (Sandbox Code Playgroud)
你需要这样称呼它。请参阅本节了解更多详细信息。
const StyledTextField = styled('div')(({ theme }) => `
margin: ${theme.spacing(1)};
background-color: ${theme.palette.primary.main};
/* ... */
`);
Run Code Online (Sandbox Code Playgroud)
或者您也可以使用 JS 对象,如文档中所示:
const StyledTextField = styled('div')(({ theme }) => ({
margin: theme.spacing(1),
backgroundColor: theme.palette.primary.main,
// ...
}));
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7020 次 |
最近记录: |