{"id":19849021,"url":"https://github.com/icorbrey/react-context-stateful","last_synced_at":"2026-05-09T16:05:46.401Z","repository":{"id":127529868,"uuid":"278719576","full_name":"icorbrey/react-context-stateful","owner":"icorbrey","description":"A simple wrapper that makes it easy to create simple, stateful contexts.","archived":false,"fork":false,"pushed_at":"2020-10-12T20:44:45.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-25T14:13:57.273Z","etag":null,"topics":["react","react-context","react-wrapper","showcase","stateful"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/react-context-stateful","language":"TypeScript","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/icorbrey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":"icorbrey","tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2020-07-10T19:43:04.000Z","updated_at":"2023-08-30T19:32:48.000Z","dependencies_parsed_at":"2023-05-04T03:17:19.368Z","dependency_job_id":null,"html_url":"https://github.com/icorbrey/react-context-stateful","commit_stats":{"total_commits":18,"total_committers":2,"mean_commits":9.0,"dds":0.05555555555555558,"last_synced_commit":"fb4e64bf91baa18882f68b969a2e2decbb43bce9"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icorbrey%2Freact-context-stateful","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icorbrey%2Freact-context-stateful/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icorbrey%2Freact-context-stateful/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icorbrey%2Freact-context-stateful/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/icorbrey","download_url":"https://codeload.github.com/icorbrey/react-context-stateful/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241226842,"owners_count":19930488,"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":["react","react-context","react-wrapper","showcase","stateful"],"created_at":"2024-11-12T13:19:03.382Z","updated_at":"2025-10-15T13:32:36.352Z","avatar_url":"https://github.com/icorbrey.png","language":"TypeScript","funding_links":["https://ko-fi.com/icorbrey"],"categories":[],"sub_categories":[],"readme":"# react-context-stateful\n\nA simple wrapper that makes it easy to create simple, stateful contexts.\n\n## Install\n\n```sh\n# Using NPM\nnpm install react-context-stateful\n\n# Using Yarn\nyarn add react-context-stateful\n```\n\n## Usage\n\nTo create a stateful context, pass `createStatefulContext()` a functional\ncomponent and export its results: \n\n```js\n// TodoContext.jsx\n\nimport createStatefulContext from 'react-context-stateful'\n\nexport [\n\tuseTodo,\n\tTodoProvider\n] = createStatefulContext(Provider =\u003e ({ children }) =\u003e\n{\n\tconst [todoList, setTodoList] = useState([])\n\n\tconst addTodoItem = item =\u003e\n\t{\n\t\t// ...\n\t}\n\n\tconst popTodoItem = () =\u003e\n\t{\n\t\t// ...\n\t}\n\n\treturn (\n\t\t\u003cProvider value={ {\n\t\t\taddTodoItem,\n\t\t\tpopTodoItem\n\t\t} }\u003e\n\t\t\t{ children }\n\t\t\u003c/Provider\u003e\n\t)\n})\n```\n\nThe `Provider` component can then be used at the project root:\n\n```js\n// index.js\n\nimport { TodoProvider } from './TodoContext'\n\nReactDOM.render(\n\t\u003cTodoProvider\u003e\n\t\t\u003cApp /\u003e\n\t\u003c/TodoProvider\u003e,\n\tdocument.getElementById('root')\n)\n```\n\nThe `Context` object is then available to use in hooks:\n\n```js\n// TodoAdder.jsx\n\nconst TodoAdder = () =\u003e\n{\n\tconst { addTodoItem } = useTodo()\n\n\t// ...\n}\n\nexport default TodoAdder\n```\n\nThis package also includes support for defining your contexts with TypeScript:\n\n```ts\nimport createStatefulContext from 'react-context-stateful'\n\ntype TodoState = {\n\tpopTodoItem: () =\u003e string\n\taddTodoItem: (item: string) =\u003e void\n}\n\nexport [\n\tuseTodo,\n\tTodoProvider\n] = createStatefulContext\u003cTodoState\u003e(Provider =\u003e ({ children }) =\u003e\n{\n\tconst [todoList, setTodoList] = useState\u003cstring[]\u003e([])\n\n\tconst addTodoItem = (item: string) =\u003e\n\t{\n\t\t// ...\n\t}\n\n\tconst popTodoItem = (): string =\u003e\n\t{\n\t\t// ...\n\t}\n\n\treturn (\n\t\t\u003cProvider value={ {\n\t\t\taddTodoItem,\n\t\t\tpopTodoItem\n\t\t} }\u003e\n\t\t\t{ children }\n\t\t\u003c/Provider\u003e\n\t)\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficorbrey%2Freact-context-stateful","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ficorbrey%2Freact-context-stateful","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficorbrey%2Freact-context-stateful/lists"}