Answer the question
In order to leave comments, you need to log in
How can I change the background color of only the selected button, and not all of them, when the button is clicked?
I remove the block by key. How can I change the background color of only the selected button, and not all of them, when the button is clicked?
let btn = this.state.change ? "clinic-card__bookmark" : "clinic-card__bookmark-active";
function handleClick(e) {
e.preventDefault();
}
return <div className="search-result-list" key={clinic.ID}>
<div className="search-result__card card-shadow">
<div className="clinic-card">
<h2 className="clinic-card__title">
{clinic.NAME}
<div className={btn_class} onClick={handleClick}>.....
Answer the question
In order to leave comments, you need to log in
const Button = () => {
const [state, setState] = useState(false);
const onClickButton = () => setState(state => !state);
return (
<div className={state ? "btn-active" : "btn"} onClick={onClickButton}>
Button
</div>
);
};
const Buttons = () => {
return (
<div>
<Button />
<Button />
<Button />
</div>
);
};
const App = () => <Buttons />;
ReactDOM.render(<App/>, document.getElementById("root"));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question