launchdarkly / react-client-sdk

LaunchDarkly Client-side SDK for React.js
Other
79 stars 67 forks source link

LDProvider using Suspense #227

Open romulof opened 7 months ago

romulof commented 7 months ago

Is your feature request related to a problem? Please describe.

Current initialisation is done by HOC and/or functions what generate the provider component for you. In some setups this can be troublesome to use, for example when you don't have much control over you app initialisation.

Describe the solution you'd like

Would be amazing if we could just use <LDProvider> and until it is ready, it will trigger React suspense mode. This is easily achieved by throwing a promise object. This object is caught by <Suspense> and it renders a fallback (aka loading component) until this promise resolves.

Describe alternatives you've considered

There are definitely other alternatives, but not as simple and supported by React itself.

Additional context

N/A

yusinto commented 7 months ago

Thank you for your submission. We will discuss this internally and provide an update soon. Logged internally as 226042.

elGatoMantocko commented 1 month ago

🤔 Just curious, can't you do something like this?

const LDProvider = lazy(async () => ({ default: await asyncWithLDProvider(config) }));
return (
  <Suspense>
    <LDProvider>{children}</LDProvider>
  </Suspense>
);

Anything I should be worried about with this workaround?