Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 使用ThemeProvider时,如何在同一DOM元素上使用两个主题?_Css_Reactjs_Material Ui - Fatal编程技术网

Css 使用ThemeProvider时,如何在同一DOM元素上使用两个主题?

Css 使用ThemeProvider时,如何在同一DOM元素上使用两个主题?,css,reactjs,material-ui,Css,Reactjs,Material Ui,我想同时使用两个主题,但现在我只能使用一个元素,我不知道如何做我想做的事情 style={theme.flexRowLeft} 我如何结合flexRow和justifyRight 我正在使用Material UI的themeprovider。在一个文件中,您可以创建主题为themes.js的文件 你把: const theme = createMuiTheme({ flexRow: { display: "flex", flexDirection: "row", a

我想同时使用两个主题,但现在我只能使用一个元素,我不知道如何做我想做的事情

style={theme.flexRowLeft}
我如何结合flexRow和justifyRight


我正在使用Material UI的themeprovider。

在一个文件中,您可以创建主题为themes.js的文件 你把:

const theme = createMuiTheme({
  flexRow: {
    display: "flex",
    flexDirection: "row",
    alignItems: "center",
  },
  justifyRight: {
    justifyContent: "right",
  },
});
当您想在功能组件中使用它时,您可以编写如下内容:

export const theme = createMuiTheme({
  flexRow: {
    display: "flex",
    flexDirection: "row",
    alignItems: "center",
  },
  justifyRight: {
    justifyContent: "right",
  },
});
从“clsx”导入clsx;
从“@material ui/core/styles”导入{makeStyles}”;
constmystyles=makeStyles(主题=>({
AA:{
显示:theme.flexRow.display,
flexDirection:theme.flexRow.flexDirection,
alignItems:theme.flexRow.alignItems
},
BB:{
justifyContent:theme.justifyRight.justifyContent
}
}),{name:“StyleNameVisibleInCss”});
函数myFunctionalComponent(){
const classes=myStyles();
返回(
一些文本
)
}

在一个文件中,您可以创建主题为themes.js的文件 你把:

const theme = createMuiTheme({
  flexRow: {
    display: "flex",
    flexDirection: "row",
    alignItems: "center",
  },
  justifyRight: {
    justifyContent: "right",
  },
});
当您想在功能组件中使用它时,您可以编写如下内容:

export const theme = createMuiTheme({
  flexRow: {
    display: "flex",
    flexDirection: "row",
    alignItems: "center",
  },
  justifyRight: {
    justifyContent: "right",
  },
});
从“clsx”导入clsx;
从“@material ui/core/styles”导入{makeStyles}”;
constmystyles=makeStyles(主题=>({
AA:{
显示:theme.flexRow.display,
flexDirection:theme.flexRow.flexDirection,
alignItems:theme.flexRow.alignItems
},
BB:{
justifyContent:theme.justifyRight.justifyContent
}
}),{name:“StyleNameVisibleInCss”});
函数myFunctionalComponent(){
const classes=myStyles();
返回(
一些文本
)
}

假设您通过功能组件内的useTheme挂钩获得主题:

import clsx from "clsx";
import { makeStyles } from "@material-ui/core/styles";

const myStyles = makeStyles(theme => ({
    AA: {
        display: theme.flexRow.display,
        flexDirection: theme.flexRow.flexDirection,
        alignItems: theme.flexRow.alignItems
    },
    BB: {
        justifyContent: theme.justifyRight.justifyContent
    }
}), {name: "StyleNameVisibleInCss"});

function myFunctionalComponent() {
    const classes = myStyles();
    return (
        <div className={clsx(classes.AA, classes.BB)}> Some text </div>
    )
}
您可以尝试字符串插值:

const theme = useTheme()

例如,总的来说:

<div className={`${theme.flexRow} ${theme.justifyRight}`}/>
const someComponent=props=>{
const theme=useTheme();
return();
}
请注意,您应该使用className属性,而不是样式

假设您通过功能组件内的useTheme挂钩获得主题:

import clsx from "clsx";
import { makeStyles } from "@material-ui/core/styles";

const myStyles = makeStyles(theme => ({
    AA: {
        display: theme.flexRow.display,
        flexDirection: theme.flexRow.flexDirection,
        alignItems: theme.flexRow.alignItems
    },
    BB: {
        justifyContent: theme.justifyRight.justifyContent
    }
}), {name: "StyleNameVisibleInCss"});

function myFunctionalComponent() {
    const classes = myStyles();
    return (
        <div className={clsx(classes.AA, classes.BB)}> Some text </div>
    )
}
您可以尝试字符串插值:

const theme = useTheme()

例如,总的来说:

<div className={`${theme.flexRow} ${theme.justifyRight}`}/>
const someComponent=props=>{
const theme=useTheme();
return();
}

请注意,您应该使用className属性,而不是样式

使用clsx(从clsx导入clsx)组合多个类我假设您使用的是useStyles或类似的东西?您尝试过库组合类吗?@SelvaS据我所知,类名比clsx差使用clsx(从clsx导入clsx)要合并多个类我假设您使用的是useStyles或类似的东西?您是否尝试使用library来合并类?@SelvaS据我所知,classnames比CLSx更糟糕。如何同时使用主题和makeStyles类?我们所做的是将主题从UseStyme挂钩传递到makeStyles函数,这就是makeStyles如何“知道”您正在处理的当前主题,而不是MUI默认主题如何同时使用主题和makeStyles类?我们所做的是将主题从useTheme挂钩传递到makeStyles函数,这就是makeStyles如何“知道”您正在处理的当前主题,而不是MUI默认主题wait,如果您想使用所有flexRow主题而不必分配每个属性,该怎么办?等等,如果您想使用所有flexRow主题而不必分配每个属性,该怎么办?