{"id":20000432,"url":"https://github.com/knpwrs/react-compose-components","last_synced_at":"2025-05-04T15:32:20.643Z","repository":{"id":41817468,"uuid":"129799223","full_name":"knpwrs/react-compose-components","owner":"knpwrs","description":"A utility to flatten component pyramids in React.","archived":false,"fork":false,"pushed_at":"2023-01-03T15:15:40.000Z","size":1891,"stargazers_count":13,"open_issues_count":31,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-26T06:09:15.867Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/knpwrs.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":"2018-04-16T20:07:52.000Z","updated_at":"2022-06-29T12:02:30.000Z","dependencies_parsed_at":"2023-02-01T06:45:16.065Z","dependency_job_id":null,"html_url":"https://github.com/knpwrs/react-compose-components","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knpwrs%2Freact-compose-components","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knpwrs%2Freact-compose-components/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knpwrs%2Freact-compose-components/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knpwrs%2Freact-compose-components/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/knpwrs","download_url":"https://codeload.github.com/knpwrs/react-compose-components/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252356115,"owners_count":21734883,"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-13T05:14:44.050Z","updated_at":"2025-05-04T15:32:20.308Z","avatar_url":"https://github.com/knpwrs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-compose-components\n\n[![Dependency Status](https://img.shields.io/david/knpwrs/react-compose-components.svg)](https://david-dm.org/knpwrs/react-compose-components)\n[![devDependency Status](https://img.shields.io/david/dev/knpwrs/react-compose-components.svg)](https://david-dm.org/knpwrs/react-compose-components#info=devDependencies)\n[![Greenkeeper badge](https://badges.greenkeeper.io/knpwrs/react-compose-components.svg)](https://greenkeeper.io/)\n[![Build Status](https://img.shields.io/travis/knpwrs/react-compose-components.svg)](https://travis-ci.org/knpwrs/react-compose-components)\n[![Npm Version](https://img.shields.io/npm/v/react-compose-components.svg)](https://www.npmjs.com/package/react-compose-components)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n[![Badges](https://img.shields.io/badge/badges-8-orange.svg)](http://shields.io/)\n\nA utility to flatten component pyramids in React.\n\n## Installation\n\n```\nnpm i react-compose-components\n```\n\n## Inspiration and Usage\n\nIf you have ever worked on a large-scale React application you are probably\nfamiliar with what I refer to as a \"provider pyramid.\" Consider an application\nthat uses [`react`], [`redux`], [`glamorous`], [`react-i18next`],\n[`react-instantsearch`] (Algolia), [`react-router`], and perhaps some internal\nproviders. You could have a root component that looks something like this:\n\n```jsx\n// ...\nexport default () =\u003e (\n  \u003cRouter history={history}\u003e\n    \u003cThemeProvider theme={theme}\u003e\n      \u003cI18nextProvider i18n={i18n}\u003e\n        \u003cReduxProvider store={store}\u003e\n          \u003cInternalProvider1\u003e\n            \u003cInternalProvider2\u003e\n              \u003cApp /\u003e\n            \u003c/InternalProvider2\u003e\n          \u003c/InternalProvider1\u003e\n        \u003c/ReduxProvider\u003e\n      \u003c/I18nextProvider\u003e\n    \u003c/ThemeProvider\u003e\n  \u003c/Router\u003e\n);\n```\n\nWith this library, you can do the following:\n\n```jsx\nimport Compose from 'react-compose-components';\n//..\nexport default () =\u003e (\n  \u003cCompose\n    components={[\n      [Router, { history }],\n      [ThemeProvider, { theme }]\n      [ReduxProvider, { store }]\n      InternalProvider1,\n      InternalProvider2,\n      App,\n    ]}\n  /\u003e\n);\n```\n\nThis flattens the pyramid leading to better maintainability and cleaner VCS diffs.\n\nThe `Compose` component also accepts children:\n\n```jsx\nimport Compose from 'react-compose-components';\n//..\nexport default () =\u003e (\n  \u003cCompose\n    components={[\n      [Router, { history }],\n      [ThemeProvider, { theme }]\n      [ReduxProvider, { store }]\n      InternalProvider1,\n      InternalProvider2,\n    ]}\n  \u003e\n    \u003cApp /\u003e\n  \u003c/Compose\u003e\n);\n```\n\n## API\n\nThis package has one default export, a component called `Compose`. `Compose`\nrequires a single prop, `components`. `components` is an array of any of the\nfollowing:\n\n* A React component.\n* A string (tag name such as `'div'`).\n* A two-element array where the first element is either a React component or a\n  string, and the second element is an object representing props to pass to the\n  component.\n\n## TypeScript\n\nThis package is written in TypeScript and ships with built-in typings.\n\n## License\n\n**MIT**\n\n[`react`]: https://reactjs.org/ \"React - A JavaScript Library for Building User Interfaces\"\n[`redux`]: https://redux.js.org/ \"A Predictable State Container for JavaScript Apps\"\n[`glamorous`]: https://glamorous.rocks/ \"glamorous - React Component Styling Solved 💄\"\n[`react-i18next`]: https://react.i18next.com/ \"An Internationalization Addon for React.js\"\n[`react-instantsearch`]: https://community.algolia.com/react-instantsearch/ \"Lightning-Fast Search for React Apps\"\n[`react-router`]: https://reacttraining.com/react-router/ \"Declarative Routing for React.js\"\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknpwrs%2Freact-compose-components","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fknpwrs%2Freact-compose-components","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknpwrs%2Freact-compose-components/lists"}