0

我是 reac 的新手,这里我使用的是材质 UI。

我设计了以下样式组件。

const StyledDefaultText = styled(Typography)<ISortBySelector>(({ fontSize }) => ({
  fontSize: fontSize ? fontSize : '12px',
  fontWeight: 'bold',
  letterSpacing: fontSize ? '0.14px' : '0.09px',
  color: '#000000'
}))

现在,在这里我添加了这个样式,这个组件仍然加载了默认样式,这些样式用于typography. 它不应用样式组件中的样式。谁能帮我这个 ?

4

1 回答 1

1

问题是,您的样式是在 material-ui 库的样式之前加载的(最后一个获胜)。你可以像这样修复它:

import { StylesProvider } from '@material-ui/core/styles';

<StylesProvider injectFirst>
  {/* Your component tree.
      Now, you can override Material-UI's styles. */}
</StylesProvider>

请参阅:https ://material-ui.com/guides/interoperability/#controlling-priority-%EF%B8%8F-3

于 2020-04-09T20:50:55.877 回答