DEV Community

Discussion on: Implement dark mode in React 🌞🌕

Collapse
lostigeros profile image
Patryk L. • Edited on

Shouldn't you use setState with a snapshot of previous state? It should not be directly mutated.

this.setState((prevState) => ({
  isDarkThemeEnabled: !prevState.isDarkThemeEnabled
}));
Enter fullscreen mode Exit fullscreen mode
Collapse
suryaraj1 profile image
Suryaraj Bhaduri Author • Edited on

True that! Thanks for this.