Reactjs Can';t get:hover或任何伪类在react+;材料界面

Reactjs Can';t get:hover或任何伪类在react+;材料界面,reactjs,pseudo-class,es6-class,mui,jss,Reactjs,Pseudo Class,Es6 Class,Mui,Jss,我已经让所有其他样式对象工作,但由于某些原因,伪类似乎无法呈现,或者它们抛出了一个错误,我正在使用jss预设默认设置。jssTest组件下面是我尝试过的不同组合的注释示例,以及我检查它们时它们是如何呈现的 import React, { Component } from "react"; import { withStyles } from "@material-ui/core/styles"; const styles = theme => ({ root: {

我已经让所有其他样式对象工作,但由于某些原因,伪类似乎无法呈现,或者它们抛出了一个错误,我正在使用jss预设默认设置。jssTest组件下面是我尝试过的不同组合的注释示例,以及我检查它们时它们是如何呈现的

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

const styles = theme => ({
    root: {
        color: "#ff0000",
        "&:hover": {
            color: "#0000ff"
        }
    }
});

class JssTest extends Component {
    render() {
        return (
            <div>
                <h1 style={styles("").root}>JSS Test</h1>
            </div>
        );
    }
}

//<h1 classes={styles("").root}>JSS Test</h1>
//Styles nothing and Renders as
//<h1 classes="[object Object]">JSS Test</h1>

//<h1 style={styles("").root}>JSS Test</h1>
//Renders just the color but not the '&:hover'
//<h1 style="color: rgb(255, 0, 0);">JSS Test</h1>

//<h1 classes={classes.root}>JSS Test</h1>
//get   Line 18:  'classes' is not defined  no-undef

//<h1 classes={styles.root}>JSS Test</h1>
//renders as
//<h1>JSS Test</h1>

export default withStyles(styles)(JssTest);
import React,{Component}来自“React”;
从“@material ui/core/styles”导入{withStyles}”;
常量样式=主题=>({
根目录:{
颜色:“ff0000”,
“&:悬停”:{
颜色:“0000ff”
}
}
});
类JssTest扩展组件{
render(){
返回(
JSS测试
);
}
}
//JSS测试
//不设置样式并渲染为
//JSS测试
//JSS测试
//仅渲染颜色,而不渲染“&:hover”
//JSS测试
//JSS测试
//获取第18行:“类”未定义无未定义
//JSS测试
//呈现为
//JSS测试
导出默认样式(样式)(JssTest);
而不是
JSS测试

使用
JSS测试

最终解决了将className设置为this.props.classes.root的问题 希望这能让其他人少浪费一天的时间

<h1 className={this.props.classes.root}>JSS Test</h1>
JSS测试

太棒了,谢谢你,我刚刚发现它正在创建自己的类,而this.props.classes.root映射到它,我会投票给你,但你不让我这么做