This dark mode component requires no additional third-party dependencies. The DarkModeScript is only needed if you want to get rid of the flash of unstyled content. A good place to put the DarkModeScript component is just under the closing body tag, although it can go almost anywhere like in the demo below.
Add component:
components/ui/dark-mode.tsx