{"id":20003270,"url":"https://github.com/mbrsagor/contextapi","last_synced_at":"2025-03-02T00:24:36.865Z","repository":{"id":111134955,"uuid":"282374619","full_name":"mbrsagor/ContextAPI","owner":"mbrsagor","description":"React content API and hooks ","archived":false,"fork":false,"pushed_at":"2021-10-06T06:53:30.000Z","size":463,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-12T13:25:28.266Z","etag":null,"topics":["context-api","hooks-api","hooks-api-react","react-context-api","react-hooks"],"latest_commit_sha":null,"homepage":"","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/mbrsagor.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":"2020-07-25T05:05:08.000Z","updated_at":"2021-10-06T06:53:33.000Z","dependencies_parsed_at":"2023-06-12T05:45:45.107Z","dependency_job_id":null,"html_url":"https://github.com/mbrsagor/ContextAPI","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbrsagor%2FContextAPI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbrsagor%2FContextAPI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbrsagor%2FContextAPI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbrsagor%2FContextAPI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mbrsagor","download_url":"https://codeload.github.com/mbrsagor/ContextAPI/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241441955,"owners_count":19963511,"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":["context-api","hooks-api","hooks-api-react","react-context-api","react-hooks"],"created_at":"2024-11-13T05:24:52.524Z","updated_at":"2025-03-02T00:24:36.842Z","avatar_url":"https://github.com/mbrsagor.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ContextAPI counter app\n\n\u003e The project is basically ContextAPI counter app.\n\n###### How to run the project on your localhost or local development server? Please bellow the command:\n\n```\ncd ContextAPI\nyarn install\nyarn start\n```\n\nRuns the app in the development mode.\\\nOpen [http://localhost:3000](http://localhost:3000) to view it in the browser.\n\n##### Example:\nStep: 1 Create a a new file `context.js`\n```javascript\nimport React, { useState, createContext } from 'react';\n\n// Create context Object\nexport const CounterContext = createContext()\n\nexport const CounterContextProvider = props =\u003e {\n    const [count, setCount] = useState(0);\n\n    return (\n        \u003cCounterContext.Provider value={[count, setCount]}\u003e\n            {props.children}\n        \u003c/CounterContext.Provider\u003e\n    )\n}\n```\n\nStep: 2 Create a a new file `counter-display.jsx`\n```javascript\nimport React, { useContext } from 'react';\nimport { CounterContext } from '../../context/counter_context';\n\n\nconst CounterDispaly = () =\u003e {\n\n    const [count] = useContext(CounterContext)\n    return (\n        \u003cdiv\u003e\n            \u003ch2\u003eCount: {count}\u003c/h2\u003e\n        \u003c/div\u003e\n    );\n}\nexport default CounterDispaly;\n```\n\nStep: 3 Create a a new file `counter-button.jsx`:\n```javascript\nimport React, { useContext } from 'react';\nimport { CounterContext } from '../../context/counter_context';\n\n\nconst CounterButton = () =\u003e {\n    const [count, setCount] = useContext(CounterContext);\n\n    const increment = () =\u003e {\n        setCount(count + 1)\n    }\n    const decrement = () =\u003e {\n        setCount(count - 1)\n    }\n    const reset = () =\u003e {\n        setCount(0)\n    }\n\n\n    return (\n        \u003cdiv\u003e\n            \u003cbutton className=\"btn btn-success btn-sm mr-2\" onClick={increment}\u003eIncrement\u003c/button\u003e\n            \u003cbutton className=\"btn btn-success btn-sm mr-2\" onClick={decrement}\u003eDecrement\u003c/button\u003e\n            \u003cbutton className=\"btn btn-danger btn-sm\" onClick={reset}\u003eReset\u003c/button\u003e\n        \u003c/div\u003e\n    )\n\n}\n\nexport default CounterButton;\n```\n\nStep: 4 Create a a new file `show-counter.jsx`:\n```javascript\nimport React from 'react';\n\nimport CounterDisplay from '../components/counter/counter-display';\nimport CounterButton from '../components/counter/counter-button';\nimport { CounterContextProvider } from '../context/counter_context';\n\n\nexport default function ShowCounter() {\n    return (\n        \u003cdiv className=\"card\"\u003e\n            \u003cdiv className=\"card-header\"\u003e\n                \u003ch4 className=\"card-title\"\u003eContext API Counter\u003c/h4\u003e\n            \u003c/div\u003e\n            \u003cdiv className=\"card-body\"\u003e\n                \u003cCounterContextProvider\u003e\n                    \u003cCounterDisplay /\u003e\n                    \u003cCounterButton /\u003e\n                \u003c/CounterContextProvider\u003e\n            \u003c/div\u003e\n        \u003c/div\u003e\n    )\n}\n```\nStep: 5 Create a a new file `app.jsx`:\n```javascript\nimport React, { Component } from \"react\";\nimport ShowCounter from './views/showCounter'\n\n\nclass App extends Component {\n  render() {\n    return (\n      \u003cdiv className=\"container\"\u003e\n        \u003cdiv className=\"row\"\u003e\n          \u003cdiv className=\"col-md-6 offset-3 text-center\"\u003e\n            \u003cShowCounter /\u003e\n            \u003cbr /\u003e\n          \u003c/div\u003e\n        \u003c/div\u003e\n      \u003c/div\u003e\n    );\n  }\n}\n\nexport default App;\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmbrsagor%2Fcontextapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmbrsagor%2Fcontextapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmbrsagor%2Fcontextapi/lists"}