react-client-sdk
react-client-sdk copied to clipboard
Re-rendering LDProvider causes all `useFlags` consumers to re-render
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 memo
ized 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
Thanks for submitting this. We will investigate and provide an update soon. Filed internally 222693.
Is there an update on this issues? We are facing the same.