launchdarkly / hello-react-native

Hello LaunchDarkly for React Native
4 stars 21 forks source link

Please provide example of using LaunchDarkly with React Native Hooks 🙏🏻 #21

Open pramahaditamaputra-ralali opened 3 years ago

pramahaditamaputra-ralali commented 3 years ago

Hi guys, could you help to update the current example or create a new one using React Native Hooks 🙏🏻 ? and also give the best practices for make a helper function to init the sdk, so i dont need to write init to each file to use the client instance.

Thank you in advance 🙏🏻

pramahaditamaputra-ralali commented 3 years ago

this one i tried, but i dont know if this is the best practice or not

Screen Shot 2021-09-20 at 12 58 15

bwoskow-ld commented 3 years ago

Hi @pramahaditamaputra-ralali,

You're correct that client.allFlags() will give you all of the currently-identified user's flags, but what you're likely after is an easy way to make these flags accessible to your React context. In order to do this we'd first want to add proper provider support using the React context pattern. We have an open feature request to add this feature. I added a note to our corresponding internal ticket (79104) to mention your hooks feature request. I will leave this GitHub issue open until your feature request is resolved.

Secondly, regarding your desire for a common initialization function -- the client.configure method is only intended to be called once, more specifically at application start time. During initialization the SDK creates long-lived connections with LaunchDarkly and these connections are meant to support feature flagging throughout your application. This function is not intended to be called in each of your components of files to initialize separate LaunchDarkly instances. Our recommendation would be to create a singleton instance and then to add it to your application context such that it is passed through your components and accessible.

Lastly, for future reference, this repository is only intended as a sample application and not our main issue tracker for the React Native SDK. Each of our SDKs are open-source and have separate repositories. For future issues with the React Native SDK I recommend filing issues here.

Cheers, @bwoskow-ld

Maltronic commented 2 years ago

It doesn't look like we're getting a hooks enabled version anytime soon which sadly makes this example and LD in general not very suitable for a lot of react native projects.