{"id":18993446,"url":"https://github.com/mdibyo/react-compose-context-consumers","last_synced_at":"2025-04-22T12:40:56.986Z","repository":{"id":71851201,"uuid":"129648845","full_name":"mDibyo/react-compose-context-consumers","owner":"mDibyo","description":"Compose React 16 ContextConsumers","archived":false,"fork":false,"pushed_at":"2018-04-16T17:21:23.000Z","size":36,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-17T01:35:37.363Z","etag":null,"topics":[],"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/mDibyo.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":"2018-04-15T20:39:49.000Z","updated_at":"2024-06-27T20:59:38.000Z","dependencies_parsed_at":"2023-04-05T20:32:38.232Z","dependency_job_id":null,"html_url":"https://github.com/mDibyo/react-compose-context-consumers","commit_stats":{"total_commits":31,"total_committers":1,"mean_commits":31.0,"dds":0.0,"last_synced_commit":"49e62624ace0127633a8d026c52dcec912f87b46"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mDibyo%2Freact-compose-context-consumers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mDibyo%2Freact-compose-context-consumers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mDibyo%2Freact-compose-context-consumers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mDibyo%2Freact-compose-context-consumers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mDibyo","download_url":"https://codeload.github.com/mDibyo/react-compose-context-consumers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250242840,"owners_count":21398207,"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":[],"created_at":"2024-11-08T17:21:26.359Z","updated_at":"2025-04-22T12:40:56.981Z","avatar_url":"https://github.com/mDibyo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-compose-context-consumers\n\nHigher Order Components for composing React's `Context.Consumer`s. [See it in action!](https://codesandbox.io/s/pmy88rk640)\n\n### Install\n\n```bash\nnpm install --save react-compose-context-consumers\n```\n\n### Introduction\n\nReact 16.3 added [a new Context API](https://reactjs.org/blog/2018/03/29/react-v-16-3.html#official-context-api) -\na `Context.Provider` component (for providing the context value), and a `Context.Consumer` component (for consuming the value).\n`Context.Consumer`s are added using render props.\nA component might want to consume multiple contexts:\n```jsx\n// example copied from https://reactjs.org/docs/context.html#consuming-multiple-contexts\n\u003cThemeContext.Consumer\u003e\n  {theme =\u003e (\n    \u003cUserContext.Consumer\u003e\n      {user =\u003e (\n        \u003cProfilePage user={user} theme={theme} /\u003e\n      )}\n    \u003c/UserContext.Consumer\u003e\n  )}\n\u003c/ThemeContext.Consumer\u003e\n```\n\nThis package provides a cleaner and more convenient way to compose `Context.Consumer`s:\n\n```jsx\nimport Compose from 'react-compose-context-consumers';\n\n...\n\n\u003cCompose theme={ThemeContext.Consumer} user={UserContext.Consumer}\u003e\n  {({ theme, user }) =\u003e (\n    \u003cProfilePage user={user} theme={theme} /\u003e\n  )}\n\u003c/Compose\u003e\n```\n\nOR\n\n```jsx\nimport { compose } from 'react-compose-context-consumers';\n\nconst Composed = compose(ThemeContext.Consumer, UserContext.Consumer);\n\n...\n\n\u003cComposed\u003e\n  {(theme, user) =\u003e (\n    \u003cProfilePage user={user} theme={theme} /\u003e\n  )}\n\u003c/Composed\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmdibyo%2Freact-compose-context-consumers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmdibyo%2Freact-compose-context-consumers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmdibyo%2Freact-compose-context-consumers/lists"}