如何在类组件中转换此功能组件

时间:2019-09-05 10:04:49

标签: reactjs material-ui

我目前正在研究material-ui和React,但无法将此功能组件转换为标题的类组件。 https://codesandbox.io/s/3kwos

1 个答案:

答案 0 :(得分:0)

希望这会有所帮助。

  • 您需要将useState转换为实际状态
const [myState, setMyState] = useState('my value')

becomes

constructor(props) {
 super(props)

 this.state = {
   myState: 'my value'
 }
}

and you can just use 

this.setState({ myState: 'my new value' }) 

to update the state's value
  • 绑定功能
  • 声明类
  • 使用withStyles高阶组件使组件可以访问this.props中的“类”对象
  • 在功能列表前添加this.

https://codesandbox.io/s/material-demo-z68ip