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

Re-rendering LDProvider causes all `useFlags` consumers to re-render

Open dwilt opened this issue 1 year ago • 2 comments

Describe the bug If a parent of <LDProvider> re-renders for whatever reason, this causes the value of Provider to change which causes all consumers of useFlags to re-render. To fix this, you need to memoize the object being passed into value because it's a new object on every re-render. Read more here

To reproduce I've put together a basic codesandbox which shows this issue: https://codesandbox.io/s/laughing-wave-8lqwg9?file=/src/MyComponent.tsx

Click the "update counter" button. This updates state of the parent component. You'll notice that MyComponent, although it's memoized and has no props, still re-renders because of the useFlags hook inside of it. If you comment out useFlags, you'll see it no longer re-renders.

Expected behavior useFlags consumers shouldn't re-renders just because the LDProvider re-renders

SDK version 3.0.9

dwilt avatar Oct 25 '23 14:10 dwilt

Thanks for submitting this. We will investigate and provide an update soon. Filed internally 222693.

yusinto avatar Oct 26 '23 17:10 yusinto

Is there an update on this issues? We are facing the same.

praneybehl avatar Jul 16 '24 01:07 praneybehl