ld-redux | A library to integrate launch darkly with react redux | Access Management library
kandi X-RAY | ld-redux Summary
kandi X-RAY | ld-redux Summary
A library to integrate launch darkly with react redux
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- reduce reducer to state object
- Interpolate default module .
ld-redux Key Features
ld-redux Examples and Code Snippets
Community Discussions
Trending Discussions on ld-redux
QUESTION
Redux's Provider
component and connect
function provide a reference to the store's state to wrapped components via mapStateToProps
. As mentioned in the lovely article How to Build a Redux, this is done so that you don't need to refer to a global store object or pass data endlessly down the DOM.
This has a great advantage: the store state is DOM agnostic. You can put any two elements anywhere on the page and provide them with any data you want from the store. If you have a form for customer search and a list of customer search results... the relationship of these presentational elements doesn't affect their access to data.
As far as I can tell, Apollo-react's ApolloProvider
does not subscribe to this principle. When I wrap a component with a query using graphql
, the results of that query are provided as props to the wrapped component. If those results are needed elsewhere in the app, they must be passed manually or stored on a global reference. In particular, props returned from a graphql query cannot be passed up the DOM.
Is there a way of making ApolloProvider "provide" query results to the rest of the app in the same way redux's Provider does? Do I need to build this functionality myself? Or, better yet, am I misunderstanding something?
...ANSWER
Answered 2017-Jul-07 at 21:10Apollo uses Redux to cache the graphql query results. Essentially if you have multiple components that need the same data, just use Apollo to wrap each of them with the same graphql query. You can even go as far as defining the graphql connector once, and using that same connector to wrap your N components.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install ld-redux
In your client bootstrap, initialise the launch darkly client by invoking the init method: import createStore from '<your-project>/store'; import ldRedux from 'ld-redux'; // standard redux createStore const store = createStore(); // do this once ldRedux.init({ clientSideId: 'your-client-side-id', dispatch: store.dispatch, }); render( <Provider store={store}> <Router routes={routes} history={browserHistory}/> </Provider>, document.getElementById('reactDiv') );
Include ldReducer as one of the reducers in your app: import { combineReducers } from 'redux'; import ldRedux from 'ld-redux'; import reducers from '<your-project>/reducers'; export default combineReducers({ ...reducers, LD: ldRedux.reducer(), // Note: the LD key can be anything you want });
Use the flag: import React, {Component} from 'react'; import {connect} from 'react-redux'; const mapStateToProps = (state) => { const {featureFlagKey} = state.LD; // Note: the key LD must be the same as step 2. return { featureFlagKey, }; }; @connect(mapStateToProps) export default class Home extends Component { render() { return ( <div> { /* look ma, feature flag! */ this.props.featureFlagKey ? <div> <p>Welcome to feature toggling!</p> </div> : 'nothing' } </div> ); } }
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page