Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 17176

React Native - `require()` statement exception handling

$
0
0

TL;DR: I want to be able to require a module in react-native and handle the exception myself in case the module does not exist (instead of displaying the RedBox).


I am using moment.js's logic to choose the most suitable locale from its library of presets (https://github.com/moment/moment/tree/develop/locale), when given a requested locale.

For example, if asked for en-us, and it was not found, it will fall back to en and so forth. The code for this logic (chooseLocale, loadLocale) can be found here: https://github.com/moment/moment/blob/develop/src/lib/locale/locales.js

Basically, it tries to require the given preset. If it does not exist, it gets en exception from the require statement, catches it and moves on to the next option.

Now, my issue is trying to use this logic with react-native. The require statement is actually implemented with react-native's guardedLoadModule which handles the exception (displays red screen). In my opinion, moment's logic is not hurt by this logic, hence I would like for the RedBox to not display.

Any thoughts?


Viewing all articles
Browse latest Browse all 17176

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>