Skip to content

Commit edf111f

Browse files
Update ThemeToggle.jsx
Issues: Input not linked to state: The input checkbox should toggle the dark mode, but it's not currently linked to is DarkMode. Missing event handler for the checkbox: You need to handle the onChange event to call toggleDarkMode and pass the checked state of the checkbox. Unnecessary value attribute: The value attribute on the input is unnecessary in this context. UI feedback: You might want to use is DarkMode to conditionally render a different UI (e.g., applying a dark theme class).
1 parent d12aa92 commit edf111f

File tree

1 file changed

+39
-39
lines changed

1 file changed

+39
-39
lines changed
Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,51 @@
11
import * as React from 'react';
22

3-
43
const ThemeToggle = () => {
54
const [isDarkMode, setDarkMode] = React.useState(false);
65

7-
const toggleDarkMode = (checked) => {
8-
setDarkMode(checked);
6+
const toggleDarkMode = (event) => {
7+
setDarkMode(event.target.checked);
98
};
109

1110
return (
1211
<label className="flex cursor-pointer place-items-center">
13-
<input
14-
type="checkbox"
15-
value="synthwave"
16-
className="toggle theme-controller bg-base-content col-span-2 col-start-1 row-start-1"
17-
/>
18-
<svg
19-
className="stroke-base-100 fill-base-100 col-start-1 row-start-1"
20-
xmlns="http://www.w3.org/2000/svg"
21-
width="14"
22-
height="14"
23-
viewBox="0 0 24 24"
24-
fill="none"
25-
stroke="currentColor"
26-
strokeWidth="2"
27-
strokeLinecap="round"
28-
strokeLinejoin="round"
29-
>
30-
<circle cx="12" cy="12" r="5" />
31-
<path d="M12 1v2M12 21v2M4.2 4.2l1.4 1.4M18.4 18.4l1.4 1.4M1 12h2M21 12h2M4.2 19.8l1.4-1.4M18.4 5.6l1.4-1.4" />
32-
</svg>
33-
<svg
34-
className="stroke-base-100 fill-base-100 col-start-2 row-start-1"
35-
xmlns="http://www.w3.org/2000/svg"
36-
width="14"
37-
height="14"
38-
viewBox="0 0 24 24"
39-
fill="none"
40-
stroke="currentColor"
41-
strokeWidth="2"
42-
strokeLinecap="round"
43-
strokeLinejoin="round"
44-
>
45-
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"></path>
46-
</svg>
47-
</label>
12+
<input
13+
type="checkbox"
14+
checked={isDarkMode}
15+
onChange={toggleDarkMode}
16+
className="toggle theme-controller bg-base-content col-span-2 col-start-1 row-start-1"
17+
/>
18+
<svg
19+
className="stroke-base-100 fill-base-100 col-start-1 row-start-1"
20+
xmlns="http://www.w3.org/2000/svg"
21+
width="14"
22+
height="14"
23+
viewBox="0 0 24 24"
24+
fill="none"
25+
stroke="currentColor"
26+
strokeWidth="2"
27+
strokeLinecap="round"
28+
strokeLinejoin="round"
29+
>
30+
<circle cx="12" cy="12" r="5" />
31+
<path d="M12 1v2M12 21v2M4.2 4.2l1.4 1.4M18.4 18.4l1.4 1.4M1 12h2M21 12h2M4.2 19.8l1.4-1.4M18.4 5.6l1.4-1.4" />
32+
</svg>
33+
<svg
34+
className="stroke-base-100 fill-base-100 col-start-2 row-start-1"
35+
xmlns="http://www.w3.org/2000/svg"
36+
width="14"
37+
height="14"
38+
viewBox="0 0 24 24"
39+
fill="none"
40+
stroke="currentColor"
41+
strokeWidth="2"
42+
strokeLinecap="round"
43+
strokeLinejoin="round"
44+
>
45+
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"></path>
46+
</svg>
47+
</label>
4848
);
4949
};
5050

51-
export default ThemeToggle;
51+
export default ThemeToggle;

0 commit comments

Comments
 (0)