{"id":18322176,"url":"https://github.com/aiaaee/change-color-mode-react","last_synced_at":"2026-05-01T16:35:55.896Z","repository":{"id":250050110,"uuid":"833323378","full_name":"aiaaee/Change-Color-Mode-React","owner":"aiaaee","description":"Changing Color Mode in React and Using Localstorage to save the changes ","archived":false,"fork":false,"pushed_at":"2024-07-31T05:25:46.000Z","size":611,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-09T14:42:26.038Z","etag":null,"topics":["api","html5","htmlcssjs","javascipt","javascript","javascript-framework","json","localstorage","react","react-context-api","react-hooks","reactjs"],"latest_commit_sha":null,"homepage":"","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/aiaaee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2024-07-24T20:02:35.000Z","updated_at":"2024-08-03T12:40:15.000Z","dependencies_parsed_at":"2024-07-28T10:42:35.988Z","dependency_job_id":"e478ef6d-e717-4b20-aac5-6a19417134a3","html_url":"https://github.com/aiaaee/Change-Color-Mode-React","commit_stats":null,"previous_names":["aiaaee/change-mode-react","aiaaee/change-color-mode-react"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/aiaaee/Change-Color-Mode-React","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aiaaee%2FChange-Color-Mode-React","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aiaaee%2FChange-Color-Mode-React/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aiaaee%2FChange-Color-Mode-React/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aiaaee%2FChange-Color-Mode-React/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aiaaee","download_url":"https://codeload.github.com/aiaaee/Change-Color-Mode-React/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aiaaee%2FChange-Color-Mode-React/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32505109,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"online","status_checked_at":"2026-05-01T02:00:05.856Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["api","html5","htmlcssjs","javascipt","javascript","javascript-framework","json","localstorage","react","react-context-api","react-hooks","reactjs"],"created_at":"2024-11-05T18:23:38.219Z","updated_at":"2026-05-01T16:35:55.878Z","avatar_url":"https://github.com/aiaaee.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Change Color Mode in React\n\nIn this project I decided to create a button to change a color mode of website . at first I write jsx and styles of my website then I used React hooks for deveoping button and change it in diffrent color . \n\n![Untitled](https://github.com/user-attachments/assets/56791d84-9f24-422a-a624-7f7367473f50)\n\nafter doing stylesheets of website , started to write `Usestate` hooks to import mode base on being _true_ and _false_ condition. on the top of that we need to import changes on input to take advantage of Usestate. \nThe checked attribute in HTML is used to indicate whether a checkbox or radio button is selected by default when the page loads , so I changed checked base on my mode.\nIn the end, I was able to implement a dark mode correctly by changing the text on the screen as well as changing the background color .\n\n![mode1](https://github.com/user-attachments/assets/cd5f38cc-4f71-43a8-bf80-4a08514b49cd)\n\n\n\n## localStorage property\nThe localStorage read-only property of the window interface allows you to access a Storage object for the Document's origin; the stored data is saved across browser sessions.\n\nLocalStorage is similar to sessionStorage, except that while localStorage data has no expiration time, sessionStorage data gets cleared when the page session ends — that is, when the page is closed. (localStorage data for a document loaded in a `private browsing` or `incognito` session is cleared when the last `private` tab is closed.)\n\nSetting Items in LocalStorage\n\nTo set items in _LocalStorage_, you can use the `setItem()` method. This method is used to store objects in LocalStorage by providing a key and a value. The value can be of any data type, but it's crucial to stringify it with `JSON.stringify()` before storing it.\n\nTo set items in LocalStorage, you can use the setItem() method. This method is used to store objects in LocalStorage by providing a key and a value. The value can be of any data type, but it's crucial to stringify it with JSON.stringify() before storing it.\n```\nconst [items, setItems] = useState([]);\n\nuseEffect(() =\u003e {\nlocalStorage.setItem('items', JSON.stringify(items));\n}, [items]);\n```\nWhen retrieving data, since it was stored as a JSON string, you need to parse it back into a JavaScript object using `JSON.parse()`\n\n## Solution For my Project\n\nin my Project I dealt with changing website color mode and I thought about protecting the color mode of website base on User computer mode . so in that case I needed to use LocalStorage to cache some information about computer mode of user and I found colour mode of them base on methods of `Localstorage` : \n```\nlet changeMode = () =\u003e {\n        let initialMode = localStorage.getItem('mode')\n        if(initialMode == null){\n            if(window.matchMedia('(prefer-color-scheme:dark)').matches){\n                return true\n            }\n            else{\n                return false\n            }\n        }\n        else{\n            return JSON.parse(localStorage.getItem('mode'))\n        }\n    }\n```\n\nfor finishing off the project , we need to switch variable `changeMode` in our useState  :\n```\nlet [mode , setMode] = useState(changeMode())\n ```\n\n\nProject is visible in section [source](https://github.com/aiaaee/Change-Color-Mode-React/tree/main/ColorMode)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faiaaee%2Fchange-color-mode-react","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faiaaee%2Fchange-color-mode-react","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faiaaee%2Fchange-color-mode-react/lists"}