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

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

Open davidli3100 opened this issue 2 years ago • 5 comments

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.

davidli3100 avatar Aug 15 '23 22:08 davidli3100

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

yusinto avatar Aug 16 '23 23:08 yusinto

Thanks @yusinto!

davidli3100 avatar Aug 17 '23 00:08 davidli3100

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}`)
  }

yusinto avatar Sep 11 '23 19:09 yusinto

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.

github-actions[bot] avatar Oct 12 '23 01:10 github-actions[bot]

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

jaswindersodhi1997 avatar Oct 13 '23 16:10 jaswindersodhi1997