[英]How to change Button Color onClick Material-UI, React
I'm working on a small project and want to change the color of a button when it is clicked.我正在做一个小项目,想在单击按钮时更改按钮的颜色。 I'm not sure how to go about it and would appreciate any help.
我不确定如何 go 关于它,希望能提供任何帮助。 I'm working in React and using the Material-UI library for styling.
我正在使用 React 并使用 Material-UI 库进行样式设置。
Thank You谢谢你
import React from "react";
import Button from "@material-ui/core/Button";
export default function ButtonClick() {
const [flag, setFlag] = React.useState(true);
const handleClick = () => {
setFlag(!flag);
};
return (
<Button
onClick={handleClick}
variant="contained"
color={flag ? "primary" : "secondary"}
>
button
</Button>
);
}
Use either使用任一
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.