til / You don’t need that dependency
Dependencies are amazing. Some kind soul has researched, packaged, and released a solution to a problem for you. You just need to download, plug it in and, most of the time, it just works. No need to reinvent the wheel.
Some dependencies are absolutely necessary, but do you need all of them? Some benefits of implementing it yourself are:
- Debuggability - If something breaks, it’s all your code. This makes it easier to find and fix the issue. No need to create a reproduction, file an issue, and wait for a potential fix.
- Tailored for you - Only implement the features you actually need. You don’t have to support every use-case.
- Security - Less likelihood of ending up in a supply chain attack.
Let’s look at some examples of popular libraries in React Native.
@react-native-community/netinfo
- I only needed to check if the app has an active internet connection. ~30 lines of Swift / ~45 lines of Kotlin.react-native-config
- I needed to get environment variables into the app and change them automatically depending on the scheme/build variant. The library is basically a Ruby script that generates some native code from.env
files. One bash script for iOS and one for Android, 42 lines of code for each.react-native-webview
- I needed custom handling of URLs, so I had to create code for both platforms anyway. We also needed to patch the library since it didn’t support custom webviews in Android for the new architecture. Turns out that that code was most of what I needed for the custom webview. ~120 lines of Swift / ~90 lines of Kotlin.@react-native-cookies/cookies
- I needed to remove session cookies, only on Android. 25 lines of Kotlin.
Nothing bad about these libraries, but it seems like some of them aren’t actively maintained. They might be considered feature complete or the author just doesn’t have time and that’s absolutely fine. But, it has meant that things break and take time to get fixed now that React Native has picked up its pace of releases.
Even though removing dependencies has increased my code by a couple of hundred lines, I feel more at ease with how it actually works. It’s OK to reinvent the wheel.