{"id":26576965,"url":"https://github.com/daveschumaker/react-dark-mode-hook","last_synced_at":"2026-04-08T21:32:07.356Z","repository":{"id":83488768,"uuid":"261950345","full_name":"daveschumaker/react-dark-mode-hook","owner":"daveschumaker","description":"A React hook to determine if user's system / device has dark mode enabled","archived":false,"fork":false,"pushed_at":"2020-06-02T16:26:32.000Z","size":33,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-20T08:46:11.430Z","etag":null,"topics":["dark-mode","hooks","react","reactjs","styled-components"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/daveschumaker.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-05-07T04:36:09.000Z","updated_at":"2020-06-02T16:26:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"c48c4057-2500-4a9a-8500-43880a7fb372","html_url":"https://github.com/daveschumaker/react-dark-mode-hook","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/daveschumaker/react-dark-mode-hook","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daveschumaker%2Freact-dark-mode-hook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daveschumaker%2Freact-dark-mode-hook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daveschumaker%2Freact-dark-mode-hook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daveschumaker%2Freact-dark-mode-hook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daveschumaker","download_url":"https://codeload.github.com/daveschumaker/react-dark-mode-hook/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daveschumaker%2Freact-dark-mode-hook/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31575503,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"ssl_error","status_checked_at":"2026-04-08T14:31:17.202Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dark-mode","hooks","react","reactjs","styled-components"],"created_at":"2025-03-23T03:34:56.397Z","updated_at":"2026-04-08T21:32:07.337Z","avatar_url":"https://github.com/daveschumaker.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## React Dark Mode Hook\n\n### Determine if user's device has dark mode enabled\n\n![dark mode screenshot](https://raw.githubusercontent.com/daveschumaker/react-dark-mode-hook/master/hello_world.png)\n\n### About\n\nThis is a simple hook for React to automatically detect a device's dark mode preference (as well as any changes to it) and style your web app accordingly, using something like `ThemeProvider` from `styled-components`.\n\nIt was developed as part of a side project I was hacking around on using my personal [React Starter Kit](https://github.com/daveschumaker/react-starter), which is my own React project for quickly getting prototypes and side projects up and running.\n\nI've released this as a standard GitHub repo instead of an NPM module due to the simplicity of this hook, especially in light of [one-line packages breaking the Internet](https://news.ycombinator.com/item?id=22979245). To use it, just copy it into your project where needed.\n\nI've released this under an [MIT license](https://github.com/daveschumaker/react-dark-mode-hook/blob/master/LICENSE.md). Feel free to use as-is, fork, copy, tear apart, profit, and share as you wish.\n\n### Instructions\n\n1. Copy `useDarkMode.js` into a relevant part of your web app. i.e., `app/hooks/useDarkMode.js`\n2. Import `useDarkMode` into your web app's entry point and use it inside your functional component. Will return `true` or `false` based on your device's system-wide dark mode setting.\n\nAlternatively:\n\nYou can also force a particular theme using localStorage. This has important implications for allowing a user to override system settings or for testing your themes.\n\n`localStorage.setItem('theme', 'dark')`\n`localStorage.setItem('theme', 'light')`\n\n### Example\n\nIf you're using a library such as `styled-components`, you can do the following.\n\n```\nimport React from 'react'\nimport { ThemeProvider } from 'styled-components'\n\nimport useDarkMode from 'app/hooks/useDarkMode'\nimport { lightTheme, darkTheme } from 'app/styles/theme'\n\nconst App = () =\u003e {\n    const darkModeEnabled = useDarkMode()\n\n    \u003cThemeProvider theme={darkModeEnabled ? darkTheme : lightTheme}\u003e\n        \u003cVariousAppComponents /\u003e\n    \u003c/ThemeProvider\u003e\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaveschumaker%2Freact-dark-mode-hook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaveschumaker%2Freact-dark-mode-hook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaveschumaker%2Freact-dark-mode-hook/lists"}