{"id":22382541,"url":"https://github.com/jcoreio/react-redux-features","last_synced_at":"2025-12-31T14:11:54.282Z","repository":{"id":14538090,"uuid":"76698713","full_name":"jcoreio/react-redux-features","owner":"jcoreio","description":"React components for redux-features","archived":false,"fork":false,"pushed_at":"2023-11-14T19:14:22.000Z","size":5563,"stargazers_count":1,"open_issues_count":38,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-01T05:05:58.957Z","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/jcoreio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2016-12-17T02:15:44.000Z","updated_at":"2023-11-14T02:53:46.000Z","dependencies_parsed_at":"2024-12-05T00:14:53.071Z","dependency_job_id":"916ccab9-f05e-46f6-93da-5e4c2c0708ea","html_url":"https://github.com/jcoreio/react-redux-features","commit_stats":{"total_commits":318,"total_committers":4,"mean_commits":79.5,"dds":0.2924528301886793,"last_synced_commit":"c679a298db51b6176228f52a643bab7042fe1b35"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/jcoreio/react-redux-features","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Freact-redux-features","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Freact-redux-features/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Freact-redux-features/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Freact-redux-features/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jcoreio","download_url":"https://codeload.github.com/jcoreio/react-redux-features/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Freact-redux-features/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265871412,"owners_count":23842028,"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-12-05T00:13:24.183Z","updated_at":"2025-12-31T14:11:54.250Z","avatar_url":"https://github.com/jcoreio.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-redux-features\n\n[![CircleCI](https://circleci.com/gh/jcoreio/react-redux-features.svg?style=svg)](https://circleci.com/gh/jcoreio/react-redux-features)\n[![Coverage Status](https://codecov.io/gh/jcoreio/react-redux-features/branch/master/graph/badge.svg)](https://codecov.io/gh/jcoreio/react-redux-features)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n\n## Legacy build Notice\n\nIf you are building for legacy browsers with webpack or similar bundlers, you\nmay need to add a rule to transpile this package to ES5.\n\n## Usage\n\n```\nnpm i --save redux-features react-redux-features\n```\n\n### featureLoader(options)\n\nCreates a component that loads a feature when it will mount, if the feature isn't already loaded. You may also have\nit render a component from the feature, something about the loading status, or anything else you want.\n\n`options` may contain the following fields (\\* = required):\n\n- `featureId` _(string)_: the id of the feature to load (i.e. what you used when you called `dispatch(addFeature(id, {...}))`\n- `render` _(Function)_: an optional render function. It will be called with `{featureState, feature, props}`, where\n  `props` are all the props you pass to the created component.\n- `getFeatureStates` _(Function)_: function that takes the redux `state` and returns the feature states (default: `state =\u003e state.featureStates`)\n- `getFeatures` _(Function)_: function that takes the redux `state` and returns the features (default: `state =\u003e state.features`)\n\n#### Example\n\nYou'll probably want to create a function in your project that delegates to `featureLoader` and provides a\nconsisent UI for loading and error messages, like the following. If you need a custom `getFeatureStates` or\n`getFeatures`, you can also include those in the call to `featureLoader` so that you don't have to provide them\neverywhere you need to create a feature loader component.\n\n`myFeatureLoader.js`\n\n```es6\nimport React from 'react'\nimport { featureLoader } from 'react-redux-features'\n\nexport default function myFeatureLoader(options) {\n  const { featureId, featureName, getComponent } = options\n\n  return featureLoader({\n    featureId,\n    render: ({ featureState, feature, props }) =\u003e {\n      const Comp = getComponent \u0026\u0026 feature ? getComponent(feature) : null\n\n      if (featureState instanceof Error) {\n        return (\n          \u003cdiv className=\"alert alert-danger\"\u003e\n            Failed to load {featureName}: {featureState.message}\n          \u003c/div\u003e\n        )\n      } else if (!Comp) {\n        return (\n          \u003cdiv className=\"alert alert-loading\"\u003e\n            \u003cspan className=\"spinner\" /\u003e Loading {featureName}...\n          \u003c/div\u003e\n        )\n      }\n      return \u003cComp {...props} /\u003e\n    },\n  })\n}\n```\n\nThen you can use it throughout your project like this:\n\n```es6\nimport React from 'react'\nimport myFeatureLoader from './myFeatureLoader'\n\nconst ConfigView = myFeatureLoader({\n  featureId: 'ConfigView',\n  featureName: 'Config View',\n  getComponent: feature =\u003e feature.components.ConfigView,\n})\n\nconst configViewElem = \u003cConfigView config={...} /\u003e\n```\n\n### featureComponents(options)\n\nCreates a component that renders zero or more components from features. Unlike `featureLoader`, it doesn't\nautomatically load any features.\n\n`options` may contain the following fields:\n\n- `getFeatures` _(Function)_: function that takes the redux `state` and returns the features (default: `state =\u003e state.features`)\n- `sortFeatures` _(Function)_: function that takes the `features` and returns an array sorted however you choose. The\n  components from features rendered by the HOC will appear in this order.\n- `getComponents` _(Function)_: function that takes a `Feature` and returns a React element, React Component, or array\n  of either/both.\n\nAll props passed to the HOC will be passed through to the feature components.\n\n#### Example\n\nImagine you wanted three separate teams in your company to create subpanels for a user's account details, profile,\nand orders.\n\nBut you don't want them to have to touch the main code for the user view, which is maintained by a fourth\nteam. That team uses `featureComponents` to specify an \"insertion point\" for any other teams' subpanels:\n\n```es6\nimport React from 'react'\nimport sortBy from 'lodash.sortby'\nimport { featureComponents } from 'react-redux-features'\n\nconst UserViewSubpanels = featureComponents({\n  sortFeatures: (features) =\u003e sortBy(features, 'indexInUserView'),\n  getComponents: (feature) =\u003e feature.UserViewSubpanels,\n})\nconst UserView = ({ user }) =\u003e (\n  \u003cdiv\u003e\n    \u003ch1\u003eUser Profile\u003c/h1\u003e\n    \u003cUserViewSubpanels user={user} /\u003e\n  \u003c/div\u003e\n)\n```\n\nThe user account team could write a feature like this to insert its panel:\n\n```es6\nimport React from 'react'\nimport Panel from './Panel'\nimport store from './store'\nimport {addFeature} from 'redux-features'\n\nconst UserAccountPanel = ({user}) =\u003e (\n  \u003cPanel title=\"Account\"\u003e\n    \u003cform onSubmit={...}\u003e\n      Username: \u003cinput name=\"username\" type=\"text\" value={user.username} /\u003e\n      Password: \u003cinput name=\"password\" type=\"password\" value={user.password} /\u003e\n    \u003c/form\u003e\n  \u003c/Panel\u003e\n)\n\nstore.dispatch(addFeature('userAccount', {\n  indexInUserView: 0,\n  userViewSubpanels: UserAccountPanel\n}))\n```\n\nThe user profile team would write the following:\n\n```es6\nimport React from 'react'\nimport Panel from './Panel'\nimport store from './store'\nimport {addFeature} from 'redux-features'\n\nconst UserProfilePanel = ({user}) =\u003e (\n  \u003cPanel title=\"Profile\"\u003e\n    \u003cform onSubmit={...}\u003e\n      First name: \u003cinput name=\"firstName\" type=\"text\" value={user.firstName} /\u003e\n      Last name: \u003cinput name=\"lastName\" type=\"text\" value={user.lastName} /\u003e\n    \u003c/form\u003e\n  \u003c/Panel\u003e\n)\n\nstore.dispatch(addFeature('userProfile', {\n  indexInUserView: 1,\n  userViewSubpanels: UserProfilePanel\n}))\n```\n\nAnd the user orders team would write:\n\n```es6\nimport React from 'react'\nimport Panel from './Panel'\nimport store from './store'\nimport {addFeature} from 'redux-features'\n\nconst UserOrdersPanel = ({user}) =\u003e (\n  \u003cPanel title=\"Orders\"\u003e\n    \u003ctable\u003e\n      \u003cthead\u003e\n        \u003ctr\u003e\n          \u003ctd\u003eOrder Number\u003c/td\u003e\n          \u003ctd\u003eDate\u003c/td\u003e\n          \u003ctd\u003eItem\u003c/td\u003e\n          \u003ctd\u003eTracking Number\u003c/td\u003e\n        \u003c/tr\u003e\n      \u003c/thead\u003e\n      \u003ctbody\u003e\n        {user.orders.map((order, key) =\u003e\n          \u003ctr key={key}\u003e\n            \u003ctd\u003e{order.number}\u003c/td\u003e\n            \u003ctd\u003e{order.date}\u003c/td\u003e\n            \u003ctd\u003e{order.itemName}\u003c/td\u003e\n            \u003ctd\u003e\u003ca href={...}\u003e{order.trackingNumber}\u003c/a\u003e\u003c/td\u003e\n          \u003c/tr\u003e\n        )}\n      \u003c/tbody\u003e\n    \u003c/table\u003e\n  \u003c/Panel\u003e\n)\n\nstore.dispatch(addFeature('userOrders', {\n  indexInUserView: 2,\n  userViewSubpanels: UserOrdersPanel,\n}))\n```\n\n### featureContent(options)\n\nThis is very similar to `featureComponents`, but it works a bit differently. It was designed for getting routes\n(for `react-router`) from features.\n\n`featureContent(...)` creates a FeatureContent component that gets some content from zero or more features in your\nstore, makes an array of all the content, and then passes the array to a child rendering function.\n\n`options` may contain the following fields:\n\n- `getFeatures` _(Function)_: function that takes the redux `state` and returns the features (default: `state =\u003e state.features`)\n- `sortFeatures` _(Function)_: function that takes the `features` and returns an array sorted however you choose. The\n  components from features rendered by the HOC will appear in this order.\n- `getContent` _(Function)_: function that takes a `Feature` and returns the content. If the content is a function,\n  it will be called with the props passed to the `\u003cFeatureContent\u003e` instance.\n\nFor `getContent: feature =\u003e feature.stuff`, a feature's `stuff` property may be a single value, an array of values, or\na function that takes the props passed to `\u003cFeatureContent\u003e` and returns either a single value or array of\nvalues.\n\n`\u003cFeatureContent\u003e` will concatenate the values from all features into a single flat array, and either render\nthose values inside a `\u003cdiv\u003e`, or if you pass a child function to `\u003cFeatureContent\u003e`, it will call that function with\nthe array of values and render what it returns.\n\n#### Example\n\nLet's say you have an app with a `/` route and an `/about` route, but you want features to be able to define additional\nroutes to go alongside these. You will put the additional routes in a feature's `rootRoutes` property. Here's how you\nwould get the routes from the features and include them with the `/` and `/about` routes:\n\n```js\nimport {featureContent} from 'react-redux-features'\n\nconst RootRoutes = featureContent({getContent: feature =\u003e feature.rootRoutes})\n\n\u003cRouter\u003e\n  \u003cRootRoutes\u003e\n    {routes =\u003e\n      \u003cSwitch\u003e\n        \u003cRoute exact path=\"/\" component={Home} /\u003e\n        \u003cRoute exact path=\"/about\" component={About} /\u003e\n        {routes}\n      \u003c/Switch\u003e\n    }\n  \u003c/RootRoutes\u003e\n\u003c/Router\u003e\n```\n\nAnd here is what some of the features might look like:\n\n```js\nconst ordersFeature = {\n  rootRoutes: [\n    \u003cRoute path=\"orders/buying\" component={BuyingOrders} /\u003e,\n    \u003cRoute path=\"orders/selling\" component={SellingOrders} /\u003e,\n  ],\n}\n\nconst UserSubRoutes = featureContent({getContent: feature =\u003e feature.userSubRoutes})\nconst userFeature = {\n  rootRoutes: \u003cRoute path=\"/user\" render={({match, location}) =\u003e\n    \u003cdiv\u003e\n      \u003cUserView match={match}\u003e\n      \u003cUserSubRoutes match={match} location={location} /\u003e\n    \u003c/div\u003e\n  }/\u003e\n}\n```\n\nIn this case `\u003cRootRoutes\u003e` will call its child function with\n\n```js\n[\n  \u003cRoute key={...} path=\"orders/buying\" component={BuyingOrders} /\u003e,\n  \u003cRoute key={...} path=\"orders/selling\" component={SellingOrders} /\u003e,\n  \u003cRoute key={...} path=\"/user\" render={...} /\u003e,\n]\n```\n\nSo the `\u003cSwitch\u003e` will render these as siblings of the `/` and `/about` routes.\n\nNotice how the `userFeature` plans to include additional routes underneath `/user`.\nThe following features use a function for `userSubRoutes`; the `UserSubRoutes` component will call the function\nwith the `match` and `location` props it received.\n\n```js\nconst userProfileFeature = {\n  dependencies: ['userFeature'],\n  userSubRoutes: ({ match }) =\u003e (\n    \u003cRoute path={`${match.url}/profile`} component={UserProfile} /\u003e\n  ),\n}\n\nconst userOrdersFeature = {\n  dependencies: ['userFeature'],\n  userSubRoutes: ({ match }) =\u003e [\n    \u003cRoute path={`${match.url}/orders/buying`} component={UserBuyingOrders} /\u003e,\n    \u003cRoute\n      path={`${match.url}/orders/selling`}\n      component={UserSellingOrders}\n    /\u003e,\n  ],\n}\n```\n\nSo the `UserSubRoutes` component will render the following children:\n\n```js\n\u003cRoute key={...} path=\"/user/profile\" component={UserProfile} /\u003e\n\u003cRoute key={...} path=\"/user/orders/buying\" component={UserBuyingOrders} /\u003e\n\u003cRoute key={...} path=\"/user/orders/selling\" component={UserSellingOrders} /\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcoreio%2Freact-redux-features","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjcoreio%2Freact-redux-features","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcoreio%2Freact-redux-features/lists"}