背景
当存在多个点击按钮时,需要提示用户点击的哪个按钮,所以要进行颜色的修改
import * as React from 'react';
import './style.css';
export default function App() {
const [active, setActive] = React.useState('red');
const handleClick = () => {
setActive('green');
};
return (
<div>
<button style={{ backgroundColor: active }} onClick={() => handleClick()}>
123
</button>
</div>
);
}