Build a component that highlights a <div> when a checkbox is selected.
EasyProblem Statement
Build a component that highlights a
when a checkbox is selected.
Sample Output
The <div> has a yellow background when the checkbox is checked.
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
import React, { useState } from "react";
const HighlightDiv = () => {
const [isChecked, setIsChecked] = useState(false);
return (
<div>
<input type="checkbox" onChange={(e) => {
// Update isChecked state
}} />
<div
style={{
backgroundColor: isChecked ? "yellow" : "transparent",
width: "200px",
height: "100px",
}}
>
Highlight me!
</div>
</div>
);
};
export default HighlightDiv;
Expected Output
The <div> has a yellow background when the checkbox is checked.