react-client-sdk icon indicating copy to clipboard operation
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

Open bethcodes opened this issue 1 year ago • 2 comments

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.

bethcodes avatar Jul 28 '22 20:07 bethcodes

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!

XieX avatar Jul 29 '22 15:07 XieX

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.

wojtekmaj avatar Sep 01 '22 06:09 wojtekmaj