[英]React Reusable Button Component - How do I properly pass a background color prop?
Right now I am trying to make a reusable button component where I can pass in a color prop to set the background depending on what component it is in.现在我正在尝试制作一个可重用的按钮组件,我可以在其中传递一个颜色道具来根据它所在的组件设置背景。
CustomButton.js自定义按钮.js
const CustomButton = ({ children, link, color }) => {
return (
<a href={link}>
<button className={styles.customButton} backgroundColor={color}>
{children}
</button>
</a>
);
};
App.js应用程序.js
<CustomButton link='/' color='red'>Test</CustomButon>
You should set the background color as part of the style property.您应该将背景颜色设置为样式属性的一部分。
const CustomButton = ({ children, link, color }) => {
return (
<a href={link}>
<button
className={styles.customButton}
style={{background: color}}
>
{children}
</button>
</a>
);
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.