简体   繁体   English

React scss 模块:子类覆盖作为道具传递的父类

[英]React scss module: child class overrides parent class pased as props

I have a component called as Overlay which has top, left , width, height, etc properties written in its scss module file我有一个名为Overlay的组件,它在其 scss 模块文件中写入了 top、left、width、height 等属性

This overlay component is used in various other components as a child.这个覆盖组件作为子组件用于各种其他组件。 I am passing className as props to this overlay component so as to override any default css given to overlay:我将 className 作为 props 传递给这个覆盖组件,以便覆盖任何给覆盖的默认 css:

const Overlay: React.FC<OverlayProps> = props => {
  const { className, onClick } = props;
  return <div id="real-overlay" className={`${className} ${styles.overlay}`} onClick={onClick}></div>;
};

But the class which is being passed as props is getting overridden by styles.overlay class from the overlay component style file.但是作为 props 传递的类正在被来自覆盖组件样式文件的styles.overlay类覆盖。

How can I make className from props take precedence?如何让 props 中的 className 优先?

您可以像这样更改顺序:

className={`${styles.overlay} ${className}`}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM