mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 07:33:07 +08:00
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.
This commit is contained in:
@@ -37,7 +37,7 @@ window.onload = () => {
|
|||||||
reflectPreference();
|
reflectPreference();
|
||||||
|
|
||||||
// now this script can find and listen for clicks on the control
|
// 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";
|
themeValue = themeValue === "light" ? "dark" : "light";
|
||||||
setPreference();
|
setPreference();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user