statsig-io / react-native

Statsig SDK for usage in React Native (non Expo) applications
ISC License
4 stars 1 forks source link

Unable to use `waitForInitialization={false}` in React Native SDK #5

Closed intergalacticspacehighway closed 4 months ago

intergalacticspacehighway commented 4 months ago

React Native triggers below error if we try to use waitForInitialization={false} in the StatsigProvider and try to read value with useConfig or similar APIs. Docs mention this error and a way to silent it but that introduces an ENV that can silent other valid errors as well 😅.

Screenshot 2024-06-14 at 2 01 48 PM

Reason

Currently, this gets triggered if we use StatsigProvider on React Native with waitForInitialization false and if we try to use for e.g. useConfig hook. The same doesn't happen on web. This is because web relies on localStorage which initialises synchronously and React native uses AsyncStorage. React Native has evolved a lot and there are better options like MMKV that can be used to save/retrieve values synchronously. I was thinking if i can quickly contribute to the feature but seems like codebase relies heavily on StatsigAsyncStorage.asyncStorage so surely requires decent amount of changes and testing. Maybe we can add waitForLoad prop so we only wait for AsyncStorage cache load instead of network too? or maybe you all can migrate to MMKV and fix this issue from the root 😄. There are surely tradeoffs on depending upon an external library or maybe some architecture change where you introduce syncPersistor, asyncPersistor adaptors etc. So users can use localStorage or AsyncStorage or MMKV.

intergalacticspacehighway commented 4 months ago

Closing as i was referring to old sdk. New sdk completely removes the waitForInitialization. Please put a big disclaimer/warning on the old sdk 😄 🙏