Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: improve DarkModeSwitch theme handling #6033

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

princeeze
Copy link

No description provided.

Copy link

netlify bot commented Dec 11, 2024

👷 Deploy request for cypress-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 71f1756

@CLAassistant
Copy link

CLAassistant commented Dec 11, 2024

CLA assistant check
All committers have signed the CLA.

@cypress-app-bot
Copy link
Collaborator

Comment on lines +11 to +16
useEffect(() => {
const savedTheme = localStorage.getItem('theme')
if (savedTheme !== colorMode) {
setColorMode(savedTheme)
}
}, [colorMode, setColorMode])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current dependency array [colorMode, setColorMode] will trigger the effect whenever colorMode changes, which can create an infinite loop since the effect itself updates colorMode. Since this effect only needs to run once to initialize the theme from localStorage, the dependency array should be []. This will ensure the effect runs only when the component mounts.

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants