基于材料ui类的组件

时间:2020-07-03 10:46:27

标签: reactjs material-ui jss

在哪里可以找到基于材料ui类的组件,而不是基于函数的组件,如果可以,我不能。 在哪里写

const classes = useClasses();
const theme = useTheme();

在我的课堂内容中?

2 个答案:

答案 0 :(得分:0)

您的用例有两个HoC,即withStyleswithTheme

用法:

import React from "react"
import { withStyles } from "@material-ui/core/styles"

const styles = theme => ({
  wrapper: {
    display: "flex",
    // ...
  }
  // ...
})

class ClassComponent extends React.Component {
  // ...

  render() {
    const { classes } = this.props
    // ...
    return (
      <div className={classes.wrapper}>
        {/* ... */}
      </div>
    )
  }
}

export const EnhancedComponent = withStyles(styles)(ClassComponent)

现在您可以渲染EnhancedComponent

答案 1 :(得分:0)

useTheme-它的一个钩子,可以与功能组件一起使用 但是,您可以将withTheme用于类组件。

引用此链接:https://material-ui.com/styles/advanced/