This repository contains the source code for the following post: https://markoskon.com/dark-mode-in-react/. The last two solutions are not mentioned in the post and they seem pretty good.
- master: Context, no local storage
- context-local-storage-bug: Context, save preferences in local storage with the bug in production.
- posts: An example of how React's hydrate treats differently attributes and text.
- context-local-storage: Context, save preferences in local storage (correct).
- css: Dan Abramov's solution from overreacted.io
- css-refactor: A refactor of the previous method.
- css-refactor-hook: The refactor with a
useTheme
hook (not linked in the post). - css-context-react-controls: An example with context and a hook where React has the control (not linked in the post).