React Native module


What is a React Native module?

A native module is a set of Javascript functions natively implemented on each platform (iOS and Android in this case). This is used if you need native functionality, if you don't already have a module that supports React Native, or if your native performance is good.

React Native apps may need access to native platform APIs that aren't available in JavaScript by default. B. Native API for accessing Apple or Google Pay. You'll probably need to reuse an existing Objective C, Swift, Java, or C ++ library or write robust multithreaded code such as image processing without reimplementing it in JavaScript.

The Native Module system exposes a JavaScript (JS) instance of a (native) Java / ObjectiveC / C ++ class as a JS object, allowing you to execute arbitrary native code from within JS. We don't expect this feature to be part of the normal development process, but it must exist. If React Native hasn't exported the native API required for your JS app, you should be able to export it yourself.

Native module setup

There are two ways to create a native module for a React Native application. Directly in iOS / Android projects of React Native application As an NPM package that you can install as a dependency of your / other React Native.

Suppose you want to access the iOS / Android native calendar API via JavaScript within a React Native application and create a calendar event. React Native does not provide a JavaScript API to communicate with the native calendar library. However, you can use the native module to write native code communicating with the native calendar API. You can then call this native code via JavaScript in your React Native application.