{"id":18106898,"url":"https://github.com/sagnik-coder24/use-reducer","last_synced_at":"2026-05-04T01:35:33.795Z","repository":{"id":260350592,"uuid":"881043627","full_name":"Sagnik-Coder24/Use-Reducer","owner":"Sagnik-Coder24","description":"A React web app demonstrating the use of the useReducer hook for state management.","archived":false,"fork":false,"pushed_at":"2024-10-30T20:34:33.000Z","size":93,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-06T06:45:56.064Z","etag":null,"topics":["css","react","use-reducer","vite"],"latest_commit_sha":null,"homepage":"https://sagnik-coder24.github.io/Use-Reducer/","language":"JavaScript","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/Sagnik-Coder24.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-10-30T20:17:08.000Z","updated_at":"2024-10-30T20:40:39.000Z","dependencies_parsed_at":"2024-10-30T21:37:32.523Z","dependency_job_id":null,"html_url":"https://github.com/Sagnik-Coder24/Use-Reducer","commit_stats":null,"previous_names":["sagnik-coder24/use-reducer"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sagnik-Coder24%2FUse-Reducer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sagnik-Coder24%2FUse-Reducer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sagnik-Coder24%2FUse-Reducer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sagnik-Coder24%2FUse-Reducer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Sagnik-Coder24","download_url":"https://codeload.github.com/Sagnik-Coder24/Use-Reducer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247445649,"owners_count":20939953,"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":["css","react","use-reducer","vite"],"created_at":"2024-10-31T23:08:24.488Z","updated_at":"2026-05-04T01:35:33.753Z","avatar_url":"https://github.com/Sagnik-Coder24.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# React useReducer Hook Example\n\nA React web application demonstrating the use of the `useReducer` hook for state management. This app showcases how to manage complex state logic in a more predictable way.\n\n## Features\n\n- Demonstrates the use of `useReducer` hook\n- Manage complex state logic\n- Clean and maintainable code\n\n## Getting Started\n\n### Prerequisites\n\nMake sure you have the following installed:\n\n- [Node.js](https://nodejs.org/)\n- [Yarn](https://yarnpkg.com/) or [npm](https://www.npmjs.com/)\n\n### Installation\n\n1. Clone the repository:\n\n   ```bash\n   git clone https://github.com/Sagnik-Coder24/Use-Reducer.git\n   cd Use-Reducer\n   ```\n\n2. Install dependencies:\n\n   ```bash\n   yarn install\n   # or\n   npm install\n   ```\n\n### Running the App\n\n1. Start the development server:\n\n   ```bash\n   yarn dev\n   # or\n   npm run dev\n   ```\n\n2. Open your browser and go to `http://localhost:5173` to see the app in action.\n\n## Usage\n\n### Understanding `useReducer`\n\nThe `useReducer` hook is an alternative to `useState` for managing state in React components. It is particularly useful for managing complex state logic and when the next state depends on the previous state.\n\n### Example Code\n\nHere’s a simple example of how to use the `useReducer` hook in a React component:\n\n```javascript\nimport React, { useReducer } from \"react\";\n\nconst initialState = { count: 0 };\n\nfunction reducer(state, action) {\n  switch (action.type) {\n    case \"increment\":\n      return { count: state.count + 1 };\n    case \"decrement\":\n      return { count: state.count - 1 };\n    default:\n      throw new Error();\n  }\n}\n\nfunction Counter() {\n  const [state, dispatch] = useReducer(reducer, initialState);\n\n  return (\n    \u003cdiv\u003e\n      \u003cp\u003eCount: {state.count}\u003c/p\u003e\n      \u003cbutton onClick={() =\u003e dispatch({ type: \"increment\" })}\u003e+\u003c/button\u003e\n      \u003cbutton onClick={() =\u003e dispatch({ type: \"decrement\" })}\u003e-\u003c/button\u003e\n    \u003c/div\u003e\n  );\n}\n\nexport default Counter;\n```\n\n### Explanation\n\n- **Initial State:** The `initialState` object defines the initial state of the component.\n- **Reducer Function:** The `reducer` function takes the current state and an action, and returns the new state based on the action type.\n- **useReducer Hook:** The `useReducer` hook takes the reducer function and the `initialState` as arguments, and returns the current state and a dispatch function to send actions to the reducer.\n\n## Built With\n\n- [React](https://reactjs.org/)\n- [Vite](https://vitejs.dev/)\n- [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS)\n\n## Contributions\n\nWe welcome contributions from the community! Feel free to open issues and pull requests to suggest improvements, add new features, or fix bugs. Here’s how you can contribute:\n\n1. Fork the repository\n2. Create a new branch (`git checkout -b feature-branch`)\n3. Make your changes\n4. Commit your changes (`git commit -am 'Add some feature'`)\n5. Push to the branch (`git push origin feature-branch`)\n6. Open a pull request\n\n## Suggestions \u0026 Feedback\n\nIf you have suggestions or feedback on how to improve this project, feel free to post them on our [GitHub Issues](https://github.com/Sagnik-Coder24/Use-Reducer/issues) page. We love hearing your ideas and collaborating with the community!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsagnik-coder24%2Fuse-reducer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsagnik-coder24%2Fuse-reducer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsagnik-coder24%2Fuse-reducer/lists"}