From c4c9ab2246ff423698468992222c60b30422beaf Mon Sep 17 00:00:00 2001 From: satnaing Date: Mon, 28 Nov 2022 21:23:15 +0630 Subject: [PATCH] fix: add optional chaining for theme switch event listener Add optional chaining in the event listener of the theme switch button in toggle-theme.js file. This is to avoid occuring an error in the console when `light & dark theme mode` is disabled. --- public/toggle-theme.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/toggle-theme.js b/public/toggle-theme.js index 7baaa00..23ad32e 100644 --- a/public/toggle-theme.js +++ b/public/toggle-theme.js @@ -37,7 +37,7 @@ window.onload = () => { reflectPreference(); // now this script can find and listen for clicks on the control - document.querySelector("#theme-btn").addEventListener("click", () => { + document.querySelector("#theme-btn")?.addEventListener("click", () => { themeValue = themeValue === "light" ? "dark" : "light"; setPreference(); });