Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/39.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 未通过react native中material ui typescript组件中的道具注入的样式 从“@material ui/core”导入{createStyles,WithStyles}”; 常量样式=(主题:主题)=>createStyles({ 根:{} }); 接口MyProps使用样式扩展{ } 导出类MyComponent扩展组件{ 构造函数(props:MyProps){ 超级(道具); console.log(props.classes);//为什么这是未定义的? } }_Css_Reactjs_Typescript_React Native_Material Ui - Fatal编程技术网

Css 未通过react native中material ui typescript组件中的道具注入的样式 从“@material ui/core”导入{createStyles,WithStyles}”; 常量样式=(主题:主题)=>createStyles({ 根:{} }); 接口MyProps使用样式扩展{ } 导出类MyComponent扩展组件{ 构造函数(props:MyProps){ 超级(道具); console.log(props.classes);//为什么这是未定义的? } }

Css 未通过react native中material ui typescript组件中的道具注入的样式 从“@material ui/core”导入{createStyles,WithStyles}”; 常量样式=(主题:主题)=>createStyles({ 根:{} }); 接口MyProps使用样式扩展{ } 导出类MyComponent扩展组件{ 构造函数(props:MyProps){ 超级(道具); console.log(props.classes);//为什么这是未定义的? } },css,reactjs,typescript,react-native,material-ui,Css,Reactjs,Typescript,React Native,Material Ui,为什么props.classes未定义?您可以将props发送到组件,就像您调用的组件一样 import {createStyles, WithStyles} from "@material-ui/core"; const styles = (theme: Theme) => createStyles({ root: {} }); interface MyProps extends WithStyles<typeof styles> { } e

为什么props.classes未定义?

您可以将props发送到组件,就像您调用的组件一样

import {createStyles, WithStyles} from "@material-ui/core";

const styles = (theme: Theme) => createStyles({
    root: {}
});

interface MyProps extends WithStyles<typeof styles> {
}

export class MyComponent extends Component<MyProps> {

    constructor(props: MyProps) { 
        super(props);
        console.log(props.classes); // why this is undefined? 
    }
}

您可以向组件发送道具,比如您呼叫的位置

import {createStyles, WithStyles} from "@material-ui/core";

const styles = (theme: Theme) => createStyles({
    root: {}
});

interface MyProps extends WithStyles<typeof styles> {
}

export class MyComponent extends Component<MyProps> {

    constructor(props: MyProps) { 
        super(props);
        console.log(props.classes); // why this is undefined? 
    }
}

通过像这样“装饰”我的类,它终于开始工作了

<MyComponent classes={.. Any thing you want to pass here ...} />
export const MyComponent = withStyles(styles)(
    class extends Component<MyProps> {
      ...
    }
)
export const MyComponent=with样式(样式)(
类扩展组件{
...
}
)
然后你可以使用这样的样式

<MyComponent classes={.. Any thing you want to pass here ...} />
export const MyComponent = withStyles(styles)(
    class extends Component<MyProps> {
      ...
    }
)

通过像这样“装饰”我的类,它终于开始工作了

<MyComponent classes={.. Any thing you want to pass here ...} />
export const MyComponent = withStyles(styles)(
    class extends Component<MyProps> {
      ...
    }
)
export const MyComponent=with样式(样式)(
类扩展组件{
...
}
)
然后你可以使用这样的样式

<MyComponent classes={.. Any thing you want to pass here ...} />
export const MyComponent = withStyles(styles)(
    class extends Component<MyProps> {
      ...
    }
)


似乎您没有将道具“类”发送给MyComponent@NooruddinLakhani那么我该如何发送它们呢?谢谢@NooruddinLakhani,但我想在组件类签出中使用styles const,这种方式似乎你没有将道具“类”发送给MyComponent@NooruddinLakhani那么我该如何发送它们呢?谢谢@NooruddinLakhani,但我想使用这些样式组件类中的常量以这种方式签出