{"id":19976414,"url":"https://github.com/khaledalabssi/teaching_repo_context_api_intr","last_synced_at":"2025-07-15T10:34:50.111Z","repository":{"id":241946178,"uuid":"725763358","full_name":"KhaledAlabssi/TEACHING_REPO_Context_API_Intr","owner":"KhaledAlabssi","description":"Teaching materials / code-examples: Simplified Context API for Frontend course F23","archived":false,"fork":false,"pushed_at":"2024-06-02T09:25:29.000Z","size":181,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-12T10:06:53.948Z","etag":null,"topics":["classwork-demo","code-example","context-api","hands-on-demos","react-context-hooks","react-global-state-manager","teacher-student-learning","teaching-materials","use-context"],"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/KhaledAlabssi.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":"2023-11-30T20:31:03.000Z","updated_at":"2024-06-02T09:26:18.000Z","dependencies_parsed_at":"2024-11-13T03:23:42.161Z","dependency_job_id":"c9766a8d-d8e5-4acb-8f0b-a7a7e0ab8350","html_url":"https://github.com/KhaledAlabssi/TEACHING_REPO_Context_API_Intr","commit_stats":null,"previous_names":["khaledalabssi/simple_context"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KhaledAlabssi%2FTEACHING_REPO_Context_API_Intr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KhaledAlabssi%2FTEACHING_REPO_Context_API_Intr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KhaledAlabssi%2FTEACHING_REPO_Context_API_Intr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KhaledAlabssi%2FTEACHING_REPO_Context_API_Intr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KhaledAlabssi","download_url":"https://codeload.github.com/KhaledAlabssi/TEACHING_REPO_Context_API_Intr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241411546,"owners_count":19958753,"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":["classwork-demo","code-example","context-api","hands-on-demos","react-context-hooks","react-global-state-manager","teacher-student-learning","teaching-materials","use-context"],"created_at":"2024-11-13T03:23:37.565Z","updated_at":"2025-07-15T10:34:50.097Z","avatar_url":"https://github.com/KhaledAlabssi.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TEACHING REPO: Context API Introduction\nThis repository contains code and examples used for teaching \"Reactjs Context-API\" For Frontend and Full Stack Development courses\n\n## Purpose\nThese examples are intended for instructional use and demonstrate basic concepts. They are not representative of production-level code or my professional work.\n\u003chr\u003e\n\n### Steps:\n- In React project, create folder: context, then inside it, create file appContext.jsx\n- inside appContext.jsx, import createContext, useState, and useContext from react: ```import { createContext, useContext, useState} from \"react\"```. \n- inside appContext.jsx, create context called AppContext: ```const AppContext = createContext()```\n- inside appContext.jsx, create and export AppProvider arrow function: ```export const AppProvider = ({children}) =\u003e {};```\n- inside AppProvider , return AppContext.Provider with value={{}} as attribute: ```\u003cAppContext.Provider value={{}}\u003e{children}\u003c/AppContext.Provider\u003e```\n- inside AppProvider, create your states and functions. **DON'T forget to add them in the value attribute**.\n- Make sure you have the children in AppProvider and to its return\n- import and render AppProvider in \"index.js\" or in \"main.jsx\" if you are using Vite: ```\u003cAppProvider\u003e\n    \u003cApp /\u003e\n\u003c/AppProvider\u003e```\n- inside appContext.jsx \"at the bottom\" create and export custom hook called useAppContext: ```export const useAppContext = (() =\u003e {return useContext(AppContext)})```\n- Import and use useAppContext into desired components: ```const {valueName} = useAppContext()```\n\n- Your appContext.jsx should looks like: \n\n``` javascript\nimport { useContext, createContext, useState } from \"react\";\nconst AppContext = createContext()```\n\nexport const AppProvider = ({ children }) =\u003e {\n\n\n    const [name, setName] = useState(\"Khaled\")\n    function flipName() {\n        setName(\"Alabssi\")\n    }\n\n\n    return (\n        \u003cAppContext.Provider value={{ name, setName, flipName }}\u003e\n            {children}\n\n        \u003c/AppContext.Provider\u003e\n\n    )\n}\nexport const useAppContext = () =\u003e {\n    return useContext(AppContext)\n}```\n\n| Congrats: you just mastered Context API :)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhaledalabssi%2Fteaching_repo_context_api_intr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkhaledalabssi%2Fteaching_repo_context_api_intr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhaledalabssi%2Fteaching_repo_context_api_intr/lists"}