{"id":16482860,"url":"https://github.com/yusinto/ld-redux","last_synced_at":"2025-09-04T18:43:09.571Z","repository":{"id":11621411,"uuid":"70143896","full_name":"yusinto/ld-redux","owner":"yusinto","description":"A library to integrate launch darkly with react redux","archived":false,"fork":false,"pushed_at":"2022-12-08T19:05:23.000Z","size":1914,"stargazers_count":34,"open_issues_count":33,"forks_count":17,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-08-03T04:39:37.170Z","etag":null,"topics":["darkly","feature","feature-flag","feature-flags","feature-toggle","feature-toggles","flags","integration","launch","launch-darkly","launchdarkly","ld","ld-redux","ldclient","react","redux","toggle"],"latest_commit_sha":null,"homepage":"","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/yusinto.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":"2016-10-06T10:26:18.000Z","updated_at":"2023-03-23T07:28:55.000Z","dependencies_parsed_at":"2023-01-11T20:16:52.701Z","dependency_job_id":null,"html_url":"https://github.com/yusinto/ld-redux","commit_stats":null,"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"purl":"pkg:github/yusinto/ld-redux","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yusinto%2Fld-redux","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yusinto%2Fld-redux/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yusinto%2Fld-redux/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yusinto%2Fld-redux/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yusinto","download_url":"https://codeload.github.com/yusinto/ld-redux/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yusinto%2Fld-redux/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273590565,"owners_count":25133144,"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","status":"online","status_checked_at":"2025-09-04T02:00:08.968Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["darkly","feature","feature-flag","feature-flags","feature-toggle","feature-toggles","flags","integration","launch","launch-darkly","launchdarkly","ld","ld-redux","ldclient","react","redux","toggle"],"created_at":"2024-10-11T13:12:15.535Z","updated_at":"2025-09-04T18:43:09.477Z","avatar_url":"https://github.com/yusinto.png","language":"JavaScript","funding_links":[],"categories":["Open Source"],"sub_categories":[],"readme":"# ld-redux\n\n[![npm version](https://img.shields.io/npm/v/ld-redux.svg?style=flat-square)](https://www.npmjs.com/package/ld-redux) [![npm downloads](https://img.shields.io/npm/dm/ld-redux.svg?style=flat-square)](https://www.npmjs.com/package/ld-redux) [![npm](https://img.shields.io/npm/dt/ld-redux.svg?style=flat-square)](https://www.npmjs.com/package/ld-redux) [![npm](https://img.shields.io/npm/l/ld-redux.svg?style=flat-square)](https://www.npmjs.com/package/ld-redux)\n\n\u003e **A library to integrate launch darkly with react redux** :clap:\n\n[Launch Darkly](https://launchdarkly.com/faq.html) is a great tool for feature flagging and a/b testing. It has a fully capable [client-side javascript sdk](https://github.com/launchdarkly/js-client), so why this package?\n\nIf you use react redux and you want to store your feature flags as part of your redux state, this package will do that for you. It does the heavy lifting of:\n\n * Fetching your flags from launch darkly.\n * Storing it in your redux state.\n * Camel casing your keys so you can use them in code with the dot operator. The keys by default are dash separated so you can't do this out of the box with the [official sdk](https://github.com/launchdarkly/js-client).\n * Server Sent Event works as well so your app will respond live to feature flag changes without the users having to refresh the browser!\n\n## Breaking changes in v3.1\nld-redux v3.1.* is *NOT* backwards compatible! The init method now accepts dispatch instead of\nstore. Follow the quickstart example below to see this.\n\n## Installation\n\nyarn add ld-redux\n\n## Quickstart\n\n1. In your client bootstrap, initialise the launch darkly client by invoking the init method:\n\n    ```javascript\n    import createStore from '\u003cyour-project\u003e/store';\n    import ldRedux from 'ld-redux';\n\n    // standard redux createStore\n    const store = createStore();\n\n    // do this once\n    ldRedux.init({\n      clientSideId: 'your-client-side-id',\n      dispatch: store.dispatch,\n    });\n\n    render(\n      \u003cProvider store={store}\u003e\n        \u003cRouter routes={routes} history={browserHistory}/\u003e\n      \u003c/Provider\u003e,\n      document.getElementById('reactDiv')\n    );\n    ```\n\n2. Include ldReducer as one of the reducers in your app:\n\n    ```javascript\n    import { combineReducers } from 'redux';\n    import ldRedux from 'ld-redux';\n    import reducers from '\u003cyour-project\u003e/reducers';\n\n    export default combineReducers({\n      ...reducers,\n      LD: ldRedux.reducer(), // Note: the LD key can be anything you want\n    });\n    ```\n\n3. Use the flag:\n\n    ```javascript\n    import React, {Component} from 'react';\n    import {connect} from 'react-redux';\n\n    const mapStateToProps = (state) =\u003e {\n      const {featureFlagKey} = state.LD; // Note: the key LD must be the same as step 2.\n\n      return {\n        featureFlagKey,\n      };\n    };\n\n    @connect(mapStateToProps)\n    export default class Home extends Component {\n      render() {\n        return (\n          \u003cdiv\u003e\n            {\n              /* look ma, feature flag! */\n              this.props.featureFlagKey ?\n                \u003cdiv\u003e\n                  \u003cp\u003eWelcome to feature toggling!\u003c/p\u003e\n                \u003c/div\u003e\n                :\n                'nothing'\n            }\n          \u003c/div\u003e\n        );\n      }\n    }\n    ```\n\n## API\n### init({clientSideId, dispatch, flags, useCamelCaseFlagKeys, user, subscribe, options})\nThe init method accepts an object with the above properties. `clientSideId`, `dispatch` are mandatory.\n\nThe `flags` property is optional. This is an object containing all the flags you want to use and subscribe to in your app.\nIf you don't specify this, ld-redux will subscribe to all flags in your ld environment.\n\n```javascript\n// standard redux createStore\nconst store = createStore();\nconst flags = { 'feature-flag-key': false }; // only subscribe to  this one flag\n\n// do this once\nldRedux.init({\n  clientSideId: 'your-client-side-id',\n  dispatch: store.dispatch,\n  flags,\n});\n```\n\nThe `subscribe` property is optional. This defaults to true which means by default you'll get automatic live updates\nof flag changes from the server. You can turn this off and manually subscribe to flag changes through the ldClient\nobject if for some reason you don't want to get live updates.\n\nThe `user` property is optional. You can initialise the sdk with a custom user by specifying one. This must be an object containing\nat least a \"key\" property. If you don't specify a user object, ldRedux will create a default one that looks like this:\n\n```javascript\nconst defaultUser = {\n  key: uuid.v4(), // random guid\n  ip: ip.address(),\n  custom: {\n    browser: userAgentParser.getResult().browser.name,\n    device\n  }\n};\n```\n\nFor more info on the user object, see [here](http://docs.launchdarkly.com/docs/js-sdk-reference#section-users).\n\nThe `useCamelCaseFlagKeys` property is optional. This defaults to true which means by default the flags that are stored\nin redux will be camel cased. If this property is false, no transformation on the flag name will be done.\n\nThe `options` property is optional. It can be used to pass in extra options such as [Bootstrapping](https://github.com/launchdarkly/js-client#bootstrapping).\nFor example:\n\n```javascript\nldRedux.init({\n    clientSideId,\n    dispatch,\n    flags,\n    options: {\n      bootstrap: 'localStorage',\n    }\n});\n```\n\n### reducer()\nThis is ld-redux's reducer. You must include this reducer in your app as per step 2 above with any key of your choice.\nYou then use this key to retrieve your flags from redux's state.\n\n### window.ldClient\nInternally the ldRedux.init method above initialises the js sdk and stores the resultant ldClient object in window.ldClient. You can use\nthis object to access the [official sdk methods](https://github.com/launchdarkly/js-client) directly. For example, you can do things like:\n\n```javascript\n// track goals\nwindow.ldClient.track('add to cart');\n\n// change user context\nwindow.ldClient.identify({key: 'someUserId'});\n```\n\nFor more info on changing user context, see the [official documentation](http://docs.launchdarkly.com/docs/js-sdk-reference#section-changing-the-user-context).\n\n### isLDReady\nYou no longer need to deal with `isLDReady`. However if you need to, it is still available in the store. You can access it via\nthe LD state like so:\n\n```javascript\nconst mapStateToProps = (state) =\u003e {\n  const {isLDReady} = state.LD; // Note: the key LD must be the same as step 2.\n\n  return {\n    isLDReady,\n  };\n};\n```\n\nThis is useful to solve \"flickering\" issues above the fold on your front page caused by a flag transitioning from a default false value\nto true.\n\n## Example\nCheck the [example](https://github.com/yusinto/ld-redux/tree/master/example) for a fully working spa with \nreact, redux and react-router. Remember to enter your client side sdk in the client [bootstrap file](https://github.com/yusinto/ld-redux/blob/master/example/src/client/index.js) \nbefore running the example!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyusinto%2Fld-redux","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyusinto%2Fld-redux","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyusinto%2Fld-redux/lists"}