{"id":18759975,"url":"https://github.com/camilopinzon/context-api","last_synced_at":"2026-05-15T08:10:02.461Z","repository":{"id":253128031,"uuid":"842548986","full_name":"CamiloPinzon/Context-API","owner":"CamiloPinzon","description":"This is a simple React application that demonstrates how to implement a theme toggler (light/dark mode) using the Context API. The theme is managed globally and can be toggled from any component within the application.","archived":false,"fork":false,"pushed_at":"2024-08-14T15:33:35.000Z","size":34,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-29T04:34:38.050Z","etag":null,"topics":["conditional-rendering","context-api","custom-hook","react","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CamiloPinzon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-08-14T15:18:42.000Z","updated_at":"2024-08-14T20:28:57.000Z","dependencies_parsed_at":"2024-08-14T17:27:27.637Z","dependency_job_id":null,"html_url":"https://github.com/CamiloPinzon/Context-API","commit_stats":null,"previous_names":["camilopinzon/context-api"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CamiloPinzon%2FContext-API","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CamiloPinzon%2FContext-API/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CamiloPinzon%2FContext-API/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CamiloPinzon%2FContext-API/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CamiloPinzon","download_url":"https://codeload.github.com/CamiloPinzon/Context-API/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239652983,"owners_count":19675008,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["conditional-rendering","context-api","custom-hook","react","typescript"],"created_at":"2024-11-07T18:08:50.598Z","updated_at":"2025-10-26T22:31:54.831Z","avatar_url":"https://github.com/CamiloPinzon.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Theme Toggler Application\n\nThis is a simple React application that demonstrates how to implement a theme toggler (light/dark mode) using the Context API. The theme is managed globally and can be toggled from any component within the application.\n\n## Features\n\n- **Context API**: Centralized state management for the theme.\n- **Light/Dark Mode**: Toggle between light and dark themes.\n- **Custom Hook**: `useTheme` hook for easy access to theme context.\n\n## Project Setup\n\n### 1. Installation\n\nFirst, clone the repository and navigate to the project directory:\n\n```bash\ngit clone https://github.com/CamiloPinzon/Context-API.git\ncd Context-API\n```\n\nThen, install the dependencies:\n\n```bash\nnpm install\n```\n\n### 2. Running the Application\n\nTo start the development server, run:\n\n```bash\nnpm run dev\n```\n\nThis will start the application on the default Vite port (usually `http://localhost:5173`).\n\n### 3. Building for Production\n\nTo build the application for production, run:\n\n```bash\nnpm run build\n```\n\nThe optimized and minified build will be available in the `dist` directory.\n\n## Application Structure\n\n- **`src/context/ThemeContext.tsx`**: Contains the `ThemeContext`, `ThemeProvider`, and `useTheme` hook.\n- **`src/components/ThemeToggle.tsx`**: A component that toggles the theme between light and dark.\n- **`src/App.tsx`**: The main component that uses the theme context and displays the `ThemeToggle` button.\n- **`src/App.css`**: Styles for the application, including the light and dark theme classes.\n\n## Context API Implementation\n\n1. **`ThemeContext`**: A context object created using React's `createContext`. It holds the current theme and a function to toggle the theme.\n2. **`ThemeProvider`**: A provider component that wraps the application and provides the theme context to all child components.\n3. **`useTheme`**: A custom hook that allows easy access to the theme context.\n\n## How It Works\n\n- The `ThemeProvider` in `src/context/ThemeContext.tsx` manages the theme state (`light` or `dark`).\n- The `toggleTheme` function toggles the theme between `light` and `dark`.\n- The `App` component applies the current theme class to the root element, and the `ThemeToggle` component allows users to switch between themes.\n\n## Example Usage\n\n```tsx\nimport React from 'react';\nimport ThemeToggle from './components/ThemeToggle';\nimport { useTheme } from './context/ThemeContext';\nimport './App.css';\n\nconst App: React.FC = () =\u003e {\n  const { theme } = useTheme();\n\n  return (\n    \u003cdiv className={`app ${theme}`}\u003e\n      \u003ch1\u003eHello, Theme Toggler!\u003c/h1\u003e\n      \u003cThemeToggle /\u003e\n    \u003c/div\u003e\n  );\n};\n\nexport default App;\n```\n\n## License\n\nThis project is licensed under the MIT License.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcamilopinzon%2Fcontext-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcamilopinzon%2Fcontext-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcamilopinzon%2Fcontext-api/lists"}