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
Log in to submit00:00
Try your code in this preview. Submit marks it done.
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;