Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-rendering LDProvider causes all useFlags consumers to re-render #222

Open
dwilt opened this issue Oct 25, 2023 · 2 comments
Open

Re-rendering LDProvider causes all useFlags consumers to re-render #222

dwilt opened this issue Oct 25, 2023 · 2 comments

Comments

@dwilt
Copy link

dwilt commented Oct 25, 2023

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

@yusinto
Copy link
Contributor

yusinto commented Oct 26, 2023

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

@praneybehl
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants