Skip to content

Conversation

princeeze
Copy link
Contributor

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.

@princeeze princeeze closed this Dec 13, 2024
@princeeze princeeze deleted the fix/DarkModeSwitch branch December 13, 2024 10:02
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