库 React Material UI 排版中变体与组件之间的区别是什么

what is difference between variant vs component in typography for library React Material UI

我正在使用 React Material UI 组件。 排版组件有 2 个道具,变体和 component.What 是这些道具之间的区别。

一些预定义样式可以与 variant 一起使用,但要呈现的最终 HTML 元素可以用组件设置。例如您可以将 variant="body1"component="h2" 一起使用,或将 variant="body2"component="h2" 一起使用,但字体大小较小。

变体 => 您使用普通 html 标签的样式。

component => 你为根节点使用了一个 React 元素。

  1. 变体:使用普通 html 标签的样式
  2. component: 把最终结果标签做成这个标签
  3. 例如,variant="h5" component="h1"
    • 应用的样式:h5 标签
    • 最终结果标签:h1标签 (您可以检查:Chrome 浏览器 > 删除工具 > 元素选项卡)