【发布时间】:2022-01-23 03:19:29
【问题描述】:
我正在使用React 和Typescript 并尝试创建一个方形组件,该组件基于传递给组件的自定义props 我可以将高度和宽度修改为其他任何东西,我指的是可以自定义高度和宽度。
目标:目前是基于scss的正方形,怎么能有人只通过customHeight和customWidth 的道具将其更改为矩形
# shomeShape.tsx
interface Props {
customHeight?: string;
customWidth?: string;
}
const SomeShape: React.FC<Props> = (props: Props): JSX.Element => {
const { customHeight, customWidth } = props;
return (
<div className={styles.customContainer}>
Random Text
</div>
);
};
export default SomeShape;
# scss
.customContainer {
width: 100px;
height: 100px;
}
任何帮助将不胜感激
【问题讨论】:
标签: javascript reactjs typescript ecmascript-6