react-client-sdk
react-client-sdk copied to clipboard
a useFlag hook (in addition to the useFlags one) so the component doesn't rerender on any configuration change
Is your feature request related to a problem? Please describe.
When a component uses the useFlags
in an application that enables streaming, the hook returns an object that contains all the flags. Any change to any flag will cause that component to rerender.
This is particularly bad if that component, or any component downstream of it, performs expensive calculations or makes requests to a server. In the worst case, it can result in synchronized traffic spikes whenever the flag configuration is updated.
Describe the solution you'd like
I would like a hook with a signature like useFlag('flag-name')
that only rerenders the subscribed component when that specific flag changes.
Describe alternatives you've considered I considered writing this hook myself, but using custom unsupported functionality is less nice than being able to use the official SDK.
Agreed that this would be a nice addition, it's something we've talked about. There's something similar in the Vue SDK. Will let you know when we've committed to it. Thanks for opening the issue, gives it more weight!
They way LD context is built will cause components to update on every flag update anyways, but still, useFlag would be a really neat addition. For now, we ended up creating this hook ourselves to save the devs from the hassle of extracting flag on their own.