launchdarkly / react-client-sdk

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

Using `useFlags` outside of the `LDProvider` context does not raise an error #214

Open davidli3100 opened 10 months ago

davidli3100 commented 10 months ago

Take the following example code (highly simplified):

const flags = useFlags()

return <LDProvider>{children}</LDProvider>

The call to useFlags occurs outside of the LDProvider context, thus resulting in an empty flags object {}. However, this does not raise some warning/error in the console, which would be helpful for catching this in less obvious cases.

yusinto commented 10 months ago

Thank you for reporting this. We will investigate and provide an update soon. Internally logged as 213181.

davidli3100 commented 10 months ago

Thanks @yusinto!

yusinto commented 9 months ago

We could try catch the react error dispatcher is null but we follow the react's team design to let the application do this. You can easily wrap a try catch in your application this way if you choose to:

  try {
    const flags = useFlags();
  } catch(e) {
    console.log(`Provider not setup: ${e}`)
  }
github-actions[bot] commented 8 months ago

This issue is marked as stale because it has been open for 30 days without activity. Remove the stale label or comment, or this will be closed in 7 days.

jaswindersodhi1997 commented 8 months ago

Hi, is this issue still opened to work upon or is it closed? Thanks.