Skip to content

Commit 406d6b3

Browse files
committed
fix(docs): prevent runtime error in a broken clock challenge by checking element existence
1 parent 84a5696 commit 406d6b3

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/content/learn/keeping-components-pure.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,12 @@ Rendering is a *calculation*, it shouldn't try to "do" things. Can you express t
246246
```js src/Clock.js active
247247
export default function Clock({ time }) {
248248
const hours = time.getHours();
249-
if (hours >= 0 && hours <= 6) {
250-
document.getElementById('time').className = 'night';
251-
} else {
252-
document.getElementById('time').className = 'day';
249+
const timeElement = document.getElementById('time');
250+
251+
if (timeElement) {
252+
timeElement.className = hours >= 0 && hours <= 6 ? 'night' : 'day';
253253
}
254+
254255
return (
255256
<h1 id="time">
256257
{time.toLocaleTimeString()}

0 commit comments

Comments
 (0)