{"id":18338743,"url":"https://github.com/tableflip/react-provide","last_synced_at":"2025-04-09T20:35:49.012Z","repository":{"id":57342876,"uuid":"106564956","full_name":"tableflip/react-provide","owner":"tableflip","description":"React Components for putting a value in context and fishing it out","archived":false,"fork":false,"pushed_at":"2018-01-23T08:51:54.000Z","size":51,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T13:19:31.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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tableflip.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-11T14:27:26.000Z","updated_at":"2018-01-18T14:59:00.000Z","dependencies_parsed_at":"2022-09-16T02:50:41.895Z","dependency_job_id":null,"html_url":"https://github.com/tableflip/react-provide","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tableflip%2Freact-provide","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tableflip%2Freact-provide/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tableflip%2Freact-provide/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tableflip%2Freact-provide/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tableflip","download_url":"https://codeload.github.com/tableflip/react-provide/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248108353,"owners_count":21049117,"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-05T20:15:04.154Z","updated_at":"2025-04-09T20:35:48.989Z","avatar_url":"https://github.com/tableflip.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-provide\n\n[![dependencies Status](https://david-dm.org/tableflip/react-provide/status.svg)](https://david-dm.org/tableflip/react-provide) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n\n\u003e React Components for putting a value in context and fishing it out. Avoids deep chains of prop passing.\n\n## Install\n\n```sh\nnpm install react-provide\n```\n\n## Usage\n\n**api.js**\n\n```js\nimport { contextProvider, withContext } from 'react-provide'\n\nexport default class Api {\n  getItems: () =\u003e ['some', 'items']\n}\n\n// Create a Provider that'll put and object called 'api' into context\nexport const Provider = contextProvider('api')\n\n// Create a helper that pulls 'api' out of context and passes it as a prop\nexport const withApi = withContext('api')\n```\n\n**list.js**\n\n```js\nimport React from 'react'\nimport { withApi } from './api'\n\n// Use withApi to pass 'api' as a prop to the component\nexport default withApi(({ api }) =\u003e (\n  \u003cdiv\u003e{api.getItems().map((name) =\u003e name)}\u003c/div\u003e\n))\n```\n\n**main.js**\n\n```js\nimport React from 'react'\nimport ReactDOM from 'react-dom'\nimport Api, { Provider } from './api'\nimport List from './list'\n\n// Use the Provider so deeply nested components can use the api in context\nReactDOM.render(\n  \u003cProvider api={new Api()}\u003e\n    \u003cdiv\u003e\u003cList /\u003e\u003c/div\u003e\n  \u003c/Provider\u003e,\n  document.getElementById('root')\n)\n```\n\n## API\n\n### `contextProvider(key)`\n\nCreate a provider component that can be used to provide a value called `key` to nested components in context.\n\ne.g.\n\n```js\nimport { contextProvider } from 'react-provide'\n\nconst Provider = contextProvider('foo')\n\n\u003cProvider foo={'bar'}\u003e\n  {/* your component tree */}\n\u003c/Provider\u003e\n```\n\n### `withContext(key)`\n\nCreate a function that'll create a component to pull a value called `key` from context and pass it as a prop to your component.\n\ne.g.\n\n```js\nimport { withContext } from 'react-provide'\n\nclass MyComponent extends Component {\n  static propTypes = {\n    foo: PropTypes.object.isRequired\n  }\n\n  render () {\n    return \u003cdiv\u003e{this.props.foo}\u003c/div\u003e\n  }\n}\n\nexport default withContext('foo')(MyComponent)\n```\n\n## Contribute\n\nFeel free to dive in! [Open an issue](https://github.com/tableflip/react-provide/issues/new) or submit PRs.\n\n## License\n\n[MIT](LICENSE) © Alan Shaw\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftableflip%2Freact-provide","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftableflip%2Freact-provide","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftableflip%2Freact-provide/lists"}