Javascript 如何扩展材质ui组件
我想将选项卡组件与es6类进行如下操作:Javascript 如何扩展材质ui组件,javascript,reactjs,material-ui,Javascript,Reactjs,Material Ui,我想将选项卡组件与es6类进行如下操作: 从“React”导入React; 从“物料界面”导入{Tab}; 类MyTab扩展选项卡{ 建造师(道具){ 超级(道具); } render(){ 返回super.render(); } } 导出默认MyTab; 但我有一个错误: Uncaught TypeError: Cannot read property 'muiTheme' of undefined 我做错了什么?目前,即使您在ES6中工作,它似乎也需要一个“getInitialState
从“React”导入React;
从“物料界面”导入{Tab};
类MyTab扩展选项卡{
建造师(道具){
超级(道具);
}
render(){
返回super.render();
}
}
导出默认MyTab;
但我有一个错误:
Uncaught TypeError: Cannot read property 'muiTheme' of undefined
我做错了什么?目前,即使您在ES6中工作,它似乎也需要一个“getInitialState”函数。所以现在只需添加一个(忽略错误) 我还在构造函数ala ES6 React中设置了这个状态
this.state = {muiThem : ThemeManager.getMuiTheme(LightThem),};
扩展MUI组件的正确方法是使用它们的
with styles()
import React,{Component}来自“React”;
从“@material ui/core/Tab”导入选项卡;
从“@material ui/core/styles”导入{withStyles}”;
常量样式=主题=>{
返回({
myTab:{
fontFamily:“信使新”,
});
}
类MyTab扩展组件{
render(){
返回(
const{classes,…other}=this.props
}
}
导出默认样式(样式)(MyTab);
this.state = {muiThem : ThemeManager.getMuiTheme(LightThem),};
import React, { Component } from "react";
import Tab from "@material-ui/core/Tab";
import { withStyles } from "@material-ui/core/styles";
const styles = theme => {
return ({
myTab: {
fontFamily: 'Courier New',
});
}
class MyTab extends Component {
render() {
return (
const {classes, ...other} = this.props
<Tab {...other} className={classes.myTab} label="Home" />
}
}
export default withStyles(styles)(MyTab);