Options
All
  • Public
  • Public/Protected
  • All
Menu

Class LDProvider

The LDProvider is a component which accepts a config object which is used to initialize launchdarkly-js-client-sdk.

This Provider does three things:

  • It initializes the ldClient instance by calling launchdarkly-js-client-sdk initialize on componentDidMount
  • It saves all flags and the ldClient instance in the context API
  • It subscribes to flag changes and propagate them through the context API

Because the launchdarkly-js-client-sdk in only initialized on componentDidMount, your flags and the ldClient are only available after your app has mounted. This can result in a flicker due to flag changes at startup time.

This component can be used as a standalone provider. However, be mindful to only include the component once within your application. This provider is used inside the withLDProviderHOC and can be used instead to initialize the launchdarkly-js-client-sdk. For async initialization, check out the asyncWithLDProvider function

Hierarchy

Implements

  • EnhancedComponent

Index

Constructors

constructor

Properties

context

context: any

If using the new style context, re-declare this in your class to be the React.ContextType of your static contextType.

static contextType = MyContext
context!: React.ContextType<typeof MyContext>
deprecated

if used without a type annotation, or without static contextType

see

https://reactjs.org/docs/legacy-context.html

Readonly props

props: Readonly<ProviderConfig> & Readonly<{ children?: ReactNode }>

refs

refs: {}

Type declaration

  • [key: string]: ReactInstance

Readonly state

state: Readonly<HocState>

Static Optional contextType

contextType: Context<any>

If set, this.context will be set at runtime to the current value of the given Context.

Usage:

type MyContext = number
const Ctx = React.createContext<MyContext>(0)

class Foo extends React.Component {
  static contextType = Ctx
  context!: React.ContextType<typeof Ctx>
  render () {
    return <>My context's value: {this.context}</>;
  }
}
see

https://reactjs.org/docs/context.html#classcontexttype

Methods

Optional UNSAFE_componentWillMount

  • UNSAFE_componentWillMount(): void

Optional UNSAFE_componentWillReceiveProps

  • UNSAFE_componentWillReceiveProps(nextProps: Readonly<ProviderConfig>, nextContext: any): void

Optional UNSAFE_componentWillUpdate

  • UNSAFE_componentWillUpdate(nextProps: Readonly<ProviderConfig>, nextState: Readonly<HocState>, nextContext: any): void

Optional componentDidCatch

  • componentDidCatch(error: Error, errorInfo: ErrorInfo): void
  • Catches exceptions generated in descendant components. Unhandled exceptions will cause the entire component tree to unmount.

    Parameters

    • error: Error
    • errorInfo: ErrorInfo

    Returns void

componentDidMount

  • componentDidMount(): Promise<void>
  • Returns Promise<void>

componentDidUpdate

Optional componentWillMount

  • componentWillMount(): void

Optional componentWillReceiveProps

  • componentWillReceiveProps(nextProps: Readonly<ProviderConfig>, nextContext: any): void

Optional componentWillUnmount

  • componentWillUnmount(): void
  • Called immediately before a component is destroyed. Perform any necessary cleanup in this method, such as cancelled network requests, or cleaning up any DOM elements created in componentDidMount.

    Returns void

Optional componentWillUpdate

  • componentWillUpdate(nextProps: Readonly<ProviderConfig>, nextState: Readonly<HocState>, nextContext: any): void

forceUpdate

  • forceUpdate(callback?: undefined | (() => void)): void
  • Parameters

    • Optional callback: undefined | (() => void)

    Returns void

getReactOptions

  • getReactOptions(): {} | {}

Optional getSnapshotBeforeUpdate

  • getSnapshotBeforeUpdate(prevProps: Readonly<ProviderConfig>, prevState: Readonly<HocState>): any | null
  • Runs before React applies the result of render to the document, and returns an object to be given to componentDidUpdate. Useful for saving things such as scroll position before render causes changes to it.

    Note: the presence of getSnapshotBeforeUpdate prevents any of the deprecated lifecycle events from running.

    Parameters

    Returns any | null

initLDClient

  • initLDClient(): Promise<void>

render

  • render(): Element

setState

  • setState<K>(state: ((prevState: Readonly<HocState>, props: Readonly<ProviderConfig>) => Pick<HocState, K> | HocState | null) | (Pick<HocState, K> | HocState | null), callback?: undefined | (() => void)): void
  • Type parameters

    • K: keyof HocState

    Parameters

    • state: ((prevState: Readonly<HocState>, props: Readonly<ProviderConfig>) => Pick<HocState, K> | HocState | null) | (Pick<HocState, K> | HocState | null)
    • Optional callback: undefined | (() => void)

    Returns void

Optional shouldComponentUpdate

  • shouldComponentUpdate(nextProps: Readonly<ProviderConfig>, nextState: Readonly<HocState>, nextContext: any): boolean
  • Called to determine whether the change in props and state should trigger a re-render.

    Component always returns true. PureComponent implements a shallow comparison on props and state and returns true if any props or states have changed.

    If false is returned, Component#render, componentWillUpdate and componentDidUpdate will not be called.

    Parameters

    • nextProps: Readonly<ProviderConfig>
    • nextState: Readonly<HocState>
    • nextContext: any

    Returns boolean

subscribeToChanges

  • subscribeToChanges(ldClient: LDClient): void

Generated using TypeDoc