react-client-sdk icon indicating copy to clipboard operation
react-client-sdk copied to clipboard

LDProvider using Suspense

Open romulof opened this issue 2 years ago • 5 comments

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

romulof avatar Nov 23 '23 15:11 romulof

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

yusinto avatar Dec 05 '23 17:12 yusinto

🤔 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?

elGatoMantocko avatar May 28 '24 22:05 elGatoMantocko

That's an interesting approach, @elGatoMantocko. I'll give it a try.

romulof avatar Jul 22 '24 22:07 romulof