Trung BìnhReact Native iconReact Native

Khi nào cần viết Native Module thay vì tìm package có sẵn?

Quy tắc: luôn ưu tiên npm package trước. Lý do: lib có sẵn được test trên nhiều device, có CI cross-platform, được community fix bug. Tự viết = bạn own toàn bộ maintenance.

Khi cần viết native module:

1. Feature platform mới chưa có lib: vd iOS Live Activity (App Intents), Android Predictive Back gesture, Apple Watch companion. Lib mất 6–12 tháng để theo kịp.

2. Wrap SDK third-party native: Stripe, Firebase Performance, Sentry, AdMob, Branch.io. Đa số có official RN wrapper, nhưng SDK ngách (vendor riêng, banking SDK) thì phải tự wrap.

3. Performance critical: image processing real-time, video filter, ML inference, audio DSP. Tính toán nặng JS không kham, native (Metal/Vulkan/Core ML) cần.

4. Đụng platform-specific permission/hardware: Bluetooth Low Energy custom protocol, NFC ghi/đọc tag riêng, USB serial, secure element.

5. Existing native code legacy: team cũ có codebase Swift/Kotlin lớn → wrap thành module cho đỡ rewrite.

Trước khi commit viết:
- Search npm + GitHub + RN directory (reactnative.directory).
- Search Expo Modules — nhiều case Expo đã expose API platform mới.
- Issue trong lib hiện có thường được fix trong vài tuần — cân nhắc wait/contribute thay vì fork.

Build vs buy reality check: native module mất 1–2 tuần viết + maintain dài hạn. Lib có sẵn $0 + community support. Chỉ tự viết khi không thể tránh.

Xem toàn bộ React Native cùng filter theo level & chủ đề con.

Mở danh sách React Native