{"id":13780960,"url":"https://github.com/BrOrlandi/react-context-connector","last_synced_at":"2025-05-11T14:34:18.965Z","repository":{"id":65472859,"uuid":"137672712","full_name":"BrOrlandi/react-context-connector","owner":"BrOrlandi","description":"React HOC to the new Context API to keep the use as simple as React-Redux connect HOC.","archived":false,"fork":false,"pushed_at":"2018-07-10T02:55:53.000Z","size":79,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-22T13:19:48.690Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/BrOrlandi.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}},"created_at":"2018-06-17T17:20:36.000Z","updated_at":"2025-03-15T01:27:10.000Z","dependencies_parsed_at":"2023-01-25T11:15:51.145Z","dependency_job_id":null,"html_url":"https://github.com/BrOrlandi/react-context-connector","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/BrOrlandi%2Freact-context-connector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrOrlandi%2Freact-context-connector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrOrlandi%2Freact-context-connector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrOrlandi%2Freact-context-connector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BrOrlandi","download_url":"https://codeload.github.com/BrOrlandi/react-context-connector/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253580227,"owners_count":21930905,"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-08-03T18:01:21.527Z","updated_at":"2025-05-11T14:34:18.646Z","avatar_url":"https://github.com/BrOrlandi.png","language":"JavaScript","funding_links":[],"categories":["List","Libraries"],"sub_categories":[],"readme":"# react-context-connector\n[![npm version](https://badge.fury.io/js/react-context-connector.svg)](https://badge.fury.io/js/react-context-connector)\n[![Build Status](https://travis-ci.com/BrOrlandi/react-context-connector.svg?branch=master)](https://travis-ci.com/BrOrlandi/react-context-connector)\n[![Coverage Status](https://coveralls.io/repos/github/BrOrlandi/react-context-connector/badge.svg?branch=master)](https://coveralls.io/github/BrOrlandi/react-context-connector?branch=master)\n\nReact HOC to the new Context API to keep the use as simple as React-Redux connect HOC.\n\n## Usage\n\n* * *\n\n### connectContext(ContextProvider, mapContextToProps) \n\nGenerates a HOC to wrap a component with context values in props.\n\n**Parameters**\n\n**ContextProvider**: `Object`, an Object with `Consumer` attribute, like the Context object or a Custom Provider\n\n**mapContextToProps**: `function`, a functiona that receives the context from `Context.Consumer` and returns a object to be used as props for the wrapped component.\n\n**Returns**: `Component`, A HOC which pass context state into props to child component.\n\n* * *\n\n## Example\n\n### Create your Context Provider\n\n```js\nconst CounterContext = React.createContext();\n\nclass CounterProvider extends Component {\n  state = {\n    count: 0,\n    incrementCount: () =\u003e {\n      ...\n    },\n\n    decrementCount: () =\u003e {\n      ...\n    },\n  }\n\n  render() {\n    return (\n    \u003cCounterContext.Provider value={this.state}\u003e\n      {this.props.children}\n    \u003c/CounterContext.Provider\u003e\n    );\n  }\n}\n\nCounterProvider.Consumer = CounterContext.Consumer;\n```\n\n### Create your component and connect it to the Context\n\n```js\nimport connectContext from 'react-context-connector';\nimport CounterProvider from './CounterProvider';\n\nconst CounterDisplay = ({ value }) =\u003e (\n  \u003cdiv\u003e\n    Counter: {value}\n  \u003c/div\u003e\n);\n\nCounterDisplay.propTypes = {\n  value: PropTypes.number,\n};\n\n// map context state and functions to component props\nconst mapContextToProps = context =\u003e ({\n  value: context.count,\n});\n\nconst CounterDisplayWithContext = connectContext(CounterProvider,mapContextToProps)(CounterDisplay);\n\nexport default CounterDisplayWithContext;\n```\n\n\n### Create your App and wrap with the Context Provider\n\n```js\nconst App = () =\u003e (\n  \u003cCounterProvider\u003e\n    \u003cdiv\u003e\n      \u003cCounterDisplay /\u003e\n      \u003cCounterButtons /\u003e\n    \u003c/div\u003e\n  \u003c/CounterProvider\u003e\n);\n\nrender(\u003cApp /\u003e, document.getElementById(\"root\"));\n```\n\n\nCheck the example folder for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBrOrlandi%2Freact-context-connector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FBrOrlandi%2Freact-context-connector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBrOrlandi%2Freact-context-connector/lists"}