Open dkwl93 opened 4 years ago
Because we use native libraries for Android and iOS under the hood we return a promise. I will look into whether we can fetch flag state synchronously. Filed internally as 74438
Thanks @torchhound Completely forgot about the bridge... I understand this seems easy but would be a big change. Appreciate your effort!
Hi @dkwl93 we do not have a way to directly fetch flag state synchronously however in React Native 4.0 you can set a timeout on the flag fetch in both iOS and Android by passing an integer parameter to configure
.
We hit this when migrating from the web SDK to the mobile one. The web SDK returns values synchronously but the mobile one does not. This actually requires a lot of loading states to be introduced in the app for us which makes it a no-go.
Would JSI be a possible solution here?
I wrote a wrapper library that exposes a getFeatureFlag()
function that returns the latest flag value from its state synchronously. It also exposes some really nice hooks that just work. The library is still a bit new. It lacks tests and I haven't tested it on ios, but my team has been using it in our production Android app for a couple months without any issues.
https://www.npmjs.com/package/launch-darkly-react-native-client-factory
Is your feature request related to a problem? Please describe. I was wondering if there was a way to fetch the flag state synchronously (based on cached values). I've gone through the documentation and example application and each evaluation seems to return a promise.
We use feature flags to flag navigation so It's important to us for flag evaluations to be instant.
Describe the solution you'd like Synchronous way of fetching flag state (boolean)
Describe alternatives you've considered Hand rolling a caching system with redux and redux-persist that gets written on launch with
allFlags()
and gets overwritten each time a flag changes.Additional context React native