<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Himanshu Sharma</title>
    <description>The latest articles on DEV Community by Himanshu Sharma (@himanshu_sharma_747c6d9d5).</description>
    <link>https://dev.to/himanshu_sharma_747c6d9d5</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2130154%2Fedf72777-609b-42aa-ba7d-779d2fc65cfb.jpg</url>
      <title>DEV Community: Himanshu Sharma</title>
      <link>https://dev.to/himanshu_sharma_747c6d9d5</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/himanshu_sharma_747c6d9d5"/>
    <language>en</language>
    <item>
      <title>C++ in React Native: Going Beyond JavaScript for High-Performance Mobile Apps</title>
      <dc:creator>Himanshu Sharma</dc:creator>
      <pubDate>Wed, 09 Sep 2026 19:01:30 +0000</pubDate>
      <link>https://dev.to/himanshu_sharma_747c6d9d5/c-in-react-native-going-beyond-javascript-for-high-performance-mobile-apps-3ei4</link>
      <guid>https://dev.to/himanshu_sharma_747c6d9d5/c-in-react-native-going-beyond-javascript-for-high-performance-mobile-apps-3ei4</guid>
      <description>&lt;p&gt;React Native allows developers to build mobile applications using JavaScript and React while still accessing native platform capabilities.&lt;/p&gt;

&lt;p&gt;But what happens when JavaScript isn't enough?&lt;/p&gt;

&lt;p&gt;What if your application needs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;High-performance video processing&lt;/li&gt;
&lt;li&gt;Complex mathematical calculations&lt;/li&gt;
&lt;li&gt;Image or audio processing&lt;/li&gt;
&lt;li&gt;Cryptography&lt;/li&gt;
&lt;li&gt;Real-time data processing&lt;/li&gt;
&lt;li&gt;Cross-platform native logic&lt;/li&gt;
&lt;li&gt;Low-level memory control&lt;/li&gt;
&lt;li&gt;Native integrations that need better performance&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is where C++ can become a powerful addition to a React Native application.&lt;/p&gt;

&lt;p&gt;C++ isn't replacing JavaScript in React Native. Instead, it can work alongside JavaScript to handle computationally intensive or performance-critical operations.&lt;/p&gt;

&lt;p&gt;In this article, we'll understand where C++ fits into the React Native architecture, how JavaScript communicates with C++, and where this approach makes sense in real-world applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why would React Native need C++?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Most React Native applications are primarily written in JavaScript or TypeScript.&lt;/p&gt;

&lt;p&gt;A simplified architecture looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;React / TypeScript
       ↓
React Native
       ↓
Native APIs
       ↓
iOS / Android
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For many applications, this is more than enough.&lt;/p&gt;

&lt;p&gt;However, JavaScript is not always the best choice for CPU-intensive workloads.&lt;/p&gt;

&lt;p&gt;For example, imagine processing a large video frame.&lt;/p&gt;

&lt;p&gt;A JavaScript implementation might look conceptually like:&lt;/p&gt;

&lt;p&gt;const processedFrame = processVideoFrame(frame);&lt;/p&gt;

&lt;p&gt;If processVideoFrame() performs millions of calculations, the JavaScript runtime can become a bottleneck.&lt;/p&gt;

&lt;p&gt;A native implementation could instead perform the heavy processing using C++:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;JavaScript
    ↓
React Native Native Layer
    ↓
  C++
    ↓
Result
    ↓
JavaScript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important idea is:&lt;/p&gt;

&lt;p&gt;Use JavaScript for application logic and C++ where native performance or low-level processing provides a real advantage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where does C++ fit into React Native?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;React Native's architecture has evolved significantly over the years.&lt;/p&gt;

&lt;p&gt;With the newer architecture, React Native provides mechanisms that make communication between JavaScript and native code more efficient.&lt;/p&gt;

&lt;p&gt;A simplified view is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌──────────────────────────┐
│     React / TypeScript   │
└────────────┬─────────────┘
             │
             ▼
┌──────────────────────────┐
│    React Native / JS     │
│         Runtime          │
└────────────┬─────────────┘
             │
             ▼
┌──────────────────────────┐
│     Native Platform      │
│    iOS / Android         │
└────────────┬─────────────┘
             │
             ▼
┌──────────────────────────┐
│           C++            │
│ Performance-heavy logic  │
└──────────────────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;C++ can therefore become a shared native layer that sits underneath both Android and iOS implementations.&lt;/p&gt;

&lt;p&gt;This is particularly useful when you don't want to implement the same complex algorithm separately in:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Kotlin / Java
       +
Swift / Objective-C
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead, you can implement the core algorithm once in C++.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why C++ instead of Kotlin or Swift?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is one of the most important questions.&lt;/p&gt;

&lt;p&gt;Android has Kotlin/Java.&lt;/p&gt;

&lt;p&gt;iOS has Swift/Objective-C.&lt;/p&gt;

&lt;p&gt;So why introduce C++?&lt;/p&gt;

&lt;p&gt;Because C++ can provide a shared native implementation across platforms.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                React Native
                     │
              Native Interface
                     │
             ┌───────┴───────┐
             │               │
          Android           iOS
             │               │
             └───────┬───────┘
                     │
                    C++
                     │
              Shared Algorithm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Suppose you're building a custom media-processing engine.&lt;/p&gt;

&lt;p&gt;Without C++:&lt;/p&gt;

&lt;p&gt;Android → Kotlin implementation&lt;br&gt;
iOS     → Swift implementation&lt;/p&gt;

&lt;p&gt;With C++:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Android ──┐
          ├──→ C++ Engine
iOS ──────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the core algorithm can be shared.&lt;/p&gt;

&lt;p&gt;This doesn't mean that the entire application should be written in C++.&lt;/p&gt;

&lt;p&gt;Only the appropriate low-level layer should be.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Real-world use cases for C++ in React Native&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There are several situations where C++ can make sense.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Video processing&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Video is one of the most obvious examples.&lt;/p&gt;

&lt;p&gt;Applications involving:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Video encoding&lt;/li&gt;
&lt;li&gt;Video decoding&lt;/li&gt;
&lt;li&gt;Frame processing&lt;/li&gt;
&lt;li&gt;Filters&lt;/li&gt;
&lt;li&gt;Transcoding&lt;/li&gt;
&lt;li&gt;Video effects&lt;/li&gt;
&lt;li&gt;DRM-related processing&lt;/li&gt;
&lt;li&gt;Custom media pipelines&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;can benefit from native code.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;React Native UI
      ↓
Video Player
      ↓
Native Media Layer
      ↓
C++ Processing Engine
      ↓
Decoder / Renderer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A React Native application doesn't need to understand the low-level details.&lt;/p&gt;

&lt;p&gt;It can simply expose a high-level API:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;processVideo&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;input&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;videoPath&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;quality&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;high&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The heavy work can happen underneath the API.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Image processing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Consider an application that needs to process images locally.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;Resize&lt;br&gt;
Crop&lt;br&gt;
Compress&lt;br&gt;
Filter&lt;br&gt;
Detect&lt;br&gt;
Transform&lt;/p&gt;

&lt;p&gt;Processing thousands or millions of pixels repeatedly can be computationally expensive.&lt;/p&gt;

&lt;p&gt;C++ is well suited for this kind of workload.&lt;/p&gt;

&lt;p&gt;A React Native API could remain simple:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const processedImage = await ImageProcessor.resize(
  image,
  1080,
  1920
);

While internally:

React Native
     ↓
Native Module
     ↓
    C++
     ↓
Image Processing
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Cryptography&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Security-sensitive applications sometimes need native cryptographic operations.&lt;/p&gt;

&lt;p&gt;Examples include:&lt;/p&gt;

&lt;p&gt;Encryption&lt;br&gt;
Decryption&lt;br&gt;
Hashing&lt;br&gt;
Key derivation&lt;br&gt;
Secure data processing&lt;/p&gt;

&lt;p&gt;Instead of implementing complex cryptographic algorithms in JavaScript, applications can use well-tested native libraries.&lt;/p&gt;

&lt;p&gt;C++ is commonly used as the underlying implementation language for many high-performance libraries.&lt;/p&gt;

&lt;p&gt;React Native can expose only the required interface:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;encryptedData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Crypto&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encrypt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The underlying implementation can remain native.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Gaming and graphics&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Games are another obvious use case.&lt;/p&gt;

&lt;p&gt;A game engine typically needs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Physics&lt;/li&gt;
&lt;li&gt;Rendering&lt;/li&gt;
&lt;li&gt;Collision detection&lt;/li&gt;
&lt;li&gt;Animation&lt;/li&gt;
&lt;li&gt;Memory management&lt;/li&gt;
&lt;li&gt;Real-time calculations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These workloads can require extremely high performance.&lt;/p&gt;

&lt;p&gt;C++ is widely used in game engines because of its performance characteristics and low-level control.&lt;/p&gt;

&lt;p&gt;A React Native application could potentially use C++ for a specialized engine while React Native handles surrounding application UI.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. AI and machine learning&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Another interesting area is on-device AI.&lt;/p&gt;

&lt;p&gt;Imagine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;React Native
     ↓
AI Native Module
     ↓
C++ Runtime
     ↓
ML Model
     ↓
Inference Result
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The JavaScript layer could simply request:&lt;br&gt;
&lt;code&gt;&lt;br&gt;
const result = await model.predict(input);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;while the native layer performs the computationally expensive inference.&lt;/p&gt;

&lt;p&gt;This approach can be useful when inference needs to happen locally rather than sending data to a server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Complex algorithms&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;C++ becomes especially interesting when your application contains algorithms that are computationally expensive.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Large data processing&lt;/li&gt;
&lt;li&gt;Graph algorithms&lt;/li&gt;
&lt;li&gt;Signal processing&lt;/li&gt;
&lt;li&gt;Compression&lt;/li&gt;
&lt;li&gt;Search algorithms&lt;/li&gt;
&lt;li&gt;Parsing&lt;/li&gt;
&lt;li&gt;Computer vision&lt;/li&gt;
&lt;li&gt;Mathematical calculations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Instead of repeatedly executing expensive calculations in JavaScript, the core algorithm can be implemented in C++.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JavaScript → C++ communication&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is where things become technically interesting.&lt;/p&gt;

&lt;p&gt;The JavaScript application needs a way to communicate with the native implementation.&lt;/p&gt;

&lt;p&gt;Conceptually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;JavaScript
    │
    │ Function Call
    ▼
Native Interface
    │
    ▼
   C++
    │
    │ Result
    ▼
JavaScript

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const result = NativeCalculator.calculate(1000000);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The native implementation might eventually call:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;double calculate(double input) {&lt;br&gt;
    // Heavy calculation&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The JavaScript developer doesn't need to know how the calculation works.&lt;/p&gt;

&lt;p&gt;They only need to know the API contract.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is JSI?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you're serious about understanding C++ in modern React Native, JSI (JavaScript Interface) is an important concept.&lt;/p&gt;

&lt;p&gt;JSI provides a lower-level interface between JavaScript and native code.&lt;/p&gt;

&lt;p&gt;Historically, React Native applications relied heavily on asynchronous communication through the bridge.&lt;/p&gt;

&lt;p&gt;Conceptually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;JavaScript
     ↓
   Bridge
     ↓
  Native
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The newer architecture provides a different approach.&lt;/p&gt;

&lt;p&gt;JSI allows native code to interact more directly with the JavaScript runtime.&lt;/p&gt;

&lt;p&gt;Conceptually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;JavaScript Runtime
       ↕
      JSI
       ↕
   Native / C++
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This can reduce some of the overhead associated with traditional bridge-based communication.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why JSI matters for C++&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JSI itself is implemented around C++ concepts and provides a foundation for creating high-performance native integrations.&lt;/p&gt;

&lt;p&gt;This makes C++ particularly interesting for React Native developers who want to work closer to the runtime.&lt;/p&gt;

&lt;p&gt;For example, a native C++ implementation can expose functionality that JavaScript can call.&lt;/p&gt;

&lt;p&gt;Conceptually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;jsi&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Value&lt;/span&gt; &lt;span class="nf"&gt;calculate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;jsi&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Runtime&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;runtime&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;jsi&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Value&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kt"&gt;size_t&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// C++ implementation&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The JavaScript side could then interact with the exposed function.&lt;/p&gt;

&lt;p&gt;The exact implementation depends on the React Native architecture and the native module design, but the important concept is the same:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;JS
 ↓
JSI
 ↓
C++
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;TurboModules and C++&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Modern React Native also introduces TurboModules as part of the New Architecture.&lt;/p&gt;

&lt;p&gt;TurboModules provide a more efficient native module system and work with React Native's code-generation approach.&lt;/p&gt;

&lt;p&gt;A simplified architecture looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TypeScript Specification
          ↓
      Codegen
          ↓
   Native Interface
          ↓
      C++ / Native
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is particularly interesting because it allows React Native developers to define a typed contract while implementing performance-critical logic in native code.&lt;/p&gt;

&lt;p&gt;For example, a TypeScript specification could conceptually define:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;interface VideoProcessor {&lt;br&gt;
  processVideo(path: string): Promise&amp;lt;string&amp;gt;;&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The underlying implementation can then be handled natively.&lt;/p&gt;

&lt;p&gt;This creates a clean separation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Business/UI Logic
       ↓
TypeScript
       ↓
Native Contract
       ↓
C++ Implementation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Fabric and C++&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;C++ also becomes relevant when looking at Fabric, React Native's newer rendering system.&lt;/p&gt;

&lt;p&gt;Fabric moves more of the rendering infrastructure toward C++ and provides a common core across platforms.&lt;/p&gt;

&lt;p&gt;A simplified architecture is:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;React&lt;br&gt;
  ↓&lt;br&gt;
Shadow Tree&lt;br&gt;
  ↓&lt;br&gt;
Fabric&lt;br&gt;
  ↓&lt;br&gt;
C++&lt;br&gt;
  ↓&lt;br&gt;
Platform Renderer&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is one reason modern React Native developers can benefit from understanding C++.&lt;/p&gt;

&lt;p&gt;You don't necessarily need to become a C++ expert to build React Native applications.&lt;/p&gt;

&lt;p&gt;But understanding:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;pointers&lt;/li&gt;
&lt;li&gt;references&lt;/li&gt;
&lt;li&gt;memory management&lt;/li&gt;
&lt;li&gt;classes&lt;/li&gt;
&lt;li&gt;templates&lt;/li&gt;
&lt;li&gt;RAII&lt;/li&gt;
&lt;li&gt;smart pointers&lt;/li&gt;
&lt;li&gt;threading&lt;/li&gt;
&lt;li&gt;native interfaces&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;can make the architecture much easier to understand.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C++ and React Native are not competitors&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It's important not to think about this as:&lt;/p&gt;

&lt;p&gt;JavaScript OR C++&lt;/p&gt;

&lt;p&gt;Instead, think:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;JavaScript
    +
TypeScript
    +
Native APIs
    +
   C++
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each layer has a different responsibility.&lt;/p&gt;

&lt;p&gt;A practical architecture might look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌─────────────────────────────┐
│       React / TypeScript    │
│       UI + Business Logic   │
└──────────────┬──────────────┘
               │
┌──────────────▼──────────────┐
│      React Native Layer     │
│  Components + Native APIs   │
└──────────────┬──────────────┘
               │
┌──────────────▼──────────────┐
│       Native Platform       │
│    Android / iOS Layer      │
└──────────────┬──────────────┘
               │
┌──────────────▼──────────────┐
│             C++             │
│   Performance-heavy logic   │
└─────────────────────────────┘

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;When should you NOT use C++?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is just as important as understanding where C++ helps.&lt;/p&gt;

&lt;p&gt;Don't introduce C++ simply because it is faster.&lt;/p&gt;

&lt;p&gt;For a normal React Native application containing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Forms&lt;/li&gt;
&lt;li&gt;API calls&lt;/li&gt;
&lt;li&gt;Navigation&lt;/li&gt;
&lt;li&gt;Authentication&lt;/li&gt;
&lt;li&gt;Lists&lt;/li&gt;
&lt;li&gt;Basic animations&lt;/li&gt;
&lt;li&gt;Business logic&lt;/li&gt;
&lt;li&gt;Standard UI components&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;C++ is usually unnecessary.&lt;/p&gt;

&lt;p&gt;For example, there is no reason to implement:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const fullName =&lt;/code&gt;${firstName} ${lastName}&lt;code&gt;;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;in C++.&lt;/p&gt;

&lt;p&gt;That would add complexity without providing meaningful benefits.&lt;/p&gt;

&lt;p&gt;The goal should be:&lt;/p&gt;

&lt;p&gt;Use C++ only when its advantages justify the additional complexity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The cost of introducing C++&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;C++ isn't free from an engineering perspective.&lt;/p&gt;

&lt;p&gt;Once you introduce a native C++ layer, you may need to deal with:&lt;/p&gt;

&lt;p&gt;Memory management&lt;/p&gt;

&lt;p&gt;You need to understand:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pointers&lt;/li&gt;
&lt;li&gt;References&lt;/li&gt;
&lt;li&gt;Ownership&lt;/li&gt;
&lt;li&gt;Smart pointers&lt;/li&gt;
&lt;li&gt;Object lifetime&lt;/li&gt;
&lt;li&gt;Threading&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You may need to manage:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Worker threads&lt;/li&gt;
&lt;li&gt;Synchronization&lt;/li&gt;
&lt;li&gt;Race conditions&lt;/li&gt;
&lt;li&gt;Deadlocks&lt;/li&gt;
&lt;li&gt;Thread safety&lt;/li&gt;
&lt;li&gt;Build systems&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You may encounter:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CMake&lt;/li&gt;
&lt;li&gt;NDK&lt;/li&gt;
&lt;li&gt;Xcode&lt;/li&gt;
&lt;li&gt;Clang&lt;/li&gt;
&lt;li&gt;Gradle&lt;/li&gt;
&lt;li&gt;CocoaPods&lt;/li&gt;
&lt;li&gt;Debugging&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Debugging a crash can become more complicated:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;JavaScript
   ↓
React Native
   ↓
Native
   ↓
  C++
   ↓
Segmentation fault
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you need native debugging skills.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C++ can also improve your React Native career&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is an underrated benefit.&lt;/p&gt;

&lt;p&gt;React Native developers who understand native development can work on a much broader range of problems.&lt;/p&gt;

&lt;p&gt;Instead of being limited to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React&lt;/li&gt;
&lt;li&gt;JavaScript&lt;/li&gt;
&lt;li&gt;TypeScript&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;you can move toward:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;React Native
     ↓
Android / iOS
     ↓
    C++
     ↓
    JSI
     ↓
   Fabric
     ↓
TurboModules
     ↓
Native Performance
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This opens doors toward roles involving:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mobile infrastructure&lt;/li&gt;
&lt;li&gt;React Native platform engineering&lt;/li&gt;
&lt;li&gt;Media SDKs&lt;/li&gt;
&lt;li&gt;Video infrastructure&lt;/li&gt;
&lt;li&gt;Performance engineering&lt;/li&gt;
&lt;li&gt;Native SDK development&lt;/li&gt;
&lt;li&gt;C++ mobile development&lt;/li&gt;
&lt;li&gt;Cross-platform frameworks&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;A practical learning roadmap&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you're already an experienced React Native developer, I wouldn't recommend starting with an enormous C++ course.&lt;/p&gt;

&lt;p&gt;Instead, learn C++ specifically from a React Native native-development perspective.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phase 1 — C++ fundamentals&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Learn:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Variables&lt;/li&gt;
&lt;li&gt;Functions&lt;/li&gt;
&lt;li&gt;Classes&lt;/li&gt;
&lt;li&gt;Objects&lt;/li&gt;
&lt;li&gt;Constructors&lt;/li&gt;
&lt;li&gt;Destructors&lt;/li&gt;
&lt;li&gt;Pointers&lt;/li&gt;
&lt;li&gt;References&lt;/li&gt;
&lt;li&gt;const&lt;/li&gt;
&lt;li&gt;STL&lt;/li&gt;
&lt;li&gt;Vectors&lt;/li&gt;
&lt;li&gt;Maps&lt;/li&gt;
&lt;li&gt;Strings&lt;/li&gt;
&lt;li&gt;Templates&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Phase 2 — Memory management&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Focus heavily on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Stack vs Heap&lt;/li&gt;
&lt;li&gt;Pointers&lt;/li&gt;
&lt;li&gt;References&lt;/li&gt;
&lt;li&gt;RAII&lt;/li&gt;
&lt;li&gt;unique_ptr&lt;/li&gt;
&lt;li&gt;shared_ptr&lt;/li&gt;
&lt;li&gt;weak_ptr&lt;/li&gt;
&lt;li&gt;Move semantics&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These concepts become extremely useful when working with native code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phase 3 — Modern C++&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Learn:&lt;/p&gt;

&lt;p&gt;C++11&lt;br&gt;
C++14&lt;br&gt;
C++17&lt;br&gt;
C++20 basics&lt;/p&gt;

&lt;p&gt;Especially:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;auto&lt;/li&gt;
&lt;li&gt;lambda functions&lt;/li&gt;
&lt;li&gt;smart pointers&lt;/li&gt;
&lt;li&gt;move semantics&lt;/li&gt;
&lt;li&gt;range-based loops&lt;/li&gt;
&lt;li&gt;optional&lt;/li&gt;
&lt;li&gt;variant&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Phase 4 — Android NDK&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Then move into Android native development.&lt;/p&gt;

&lt;p&gt;Learn:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Android NDK&lt;/li&gt;
&lt;li&gt;CMake&lt;/li&gt;
&lt;li&gt;JNI&lt;/li&gt;
&lt;li&gt;C++&lt;/li&gt;
&lt;li&gt;Native libraries&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Architecture:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;React Native
      ↓
   Android
      ↓
     JNI
      ↓
     C++
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Phase 5 — iOS native integration&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Understand:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Objective-C++&lt;/li&gt;
&lt;li&gt;Swift ↔ Objective-C++&lt;/li&gt;
&lt;li&gt;C++ libraries&lt;/li&gt;
&lt;li&gt;Xcode&lt;/li&gt;
&lt;li&gt;CocoaPods&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You don't necessarily need to become a Swift expert.&lt;/p&gt;

&lt;p&gt;Your goal is to understand how the C++ layer can be integrated into the iOS application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phase 6 — React Native internals&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is where your existing React Native experience becomes extremely valuable.&lt;/p&gt;

&lt;p&gt;Learn:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JSI&lt;/li&gt;
&lt;li&gt;TurboModules&lt;/li&gt;
&lt;li&gt;Codegen&lt;/li&gt;
&lt;li&gt;Fabric&lt;/li&gt;
&lt;li&gt;Bridgeless Mode&lt;/li&gt;
&lt;li&gt;Hermes&lt;/li&gt;
&lt;li&gt;New Architecture&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then start reading actual React Native source code.&lt;/p&gt;

&lt;p&gt;At this point, you'll start seeing why React Native uses C++ internally.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Final thoughts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;C++ doesn't make every React Native application faster.&lt;/p&gt;

&lt;p&gt;It makes sense when you have a problem that benefits from:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;High computational performance&lt;/li&gt;
&lt;li&gt;Low-level control&lt;/li&gt;
&lt;li&gt;Native memory management&lt;/li&gt;
&lt;li&gt;Cross-platform native logic&lt;/li&gt;
&lt;li&gt;Existing C/C++ libraries&lt;/li&gt;
&lt;li&gt;Heavy media or graphics processing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For experienced React Native developers, learning C++ is therefore less about abandoning JavaScript and more about understanding what happens underneath React Native.&lt;/p&gt;

&lt;p&gt;The most powerful combination isn't:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;React Native vs C++&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It's:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;React Native + Native Development + C++&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once you understand all three layers, you can move from building React Native applications to building native-powered React Native systems.&lt;/p&gt;

&lt;p&gt;And that's a very different level of engineering.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you're already comfortable with React Native, you don't need to become a C++ specialist overnight.&lt;/p&gt;

&lt;p&gt;Start small.&lt;/p&gt;

&lt;p&gt;Learn modern C++.&lt;/p&gt;

&lt;p&gt;Understand memory management.&lt;/p&gt;

&lt;p&gt;Build a native module.&lt;/p&gt;

&lt;p&gt;Learn JSI.&lt;/p&gt;

&lt;p&gt;Understand TurboModules and Fabric.&lt;/p&gt;

&lt;p&gt;Then gradually move into the React Native internals.&lt;/p&gt;

&lt;p&gt;The goal isn't to write your entire React Native application in C++.&lt;/p&gt;

&lt;p&gt;The goal is to know when JavaScript is the right tool—and when it isn't.&lt;/p&gt;

</description>
      <category>cpp</category>
      <category>mobile</category>
      <category>performance</category>
      <category>reactnative</category>
    </item>
    <item>
      <title>A Guide to React Native Expo and Bare Bone Projects</title>
      <dc:creator>Himanshu Sharma</dc:creator>
      <pubDate>Thu, 26 Sep 2024 13:36:58 +0000</pubDate>
      <link>https://dev.to/himanshu_sharma_747c6d9d5/a-guide-to-react-native-expo-and-bare-bone-projects-3pck</link>
      <guid>https://dev.to/himanshu_sharma_747c6d9d5/a-guide-to-react-native-expo-and-bare-bone-projects-3pck</guid>
      <description>&lt;p&gt;React Native is a powerful framework for building mobile applications using JavaScript and React. It offers two main ways to start a project: using Expo or starting with a Bare Bone project. While both approaches can lead to a successful mobile app, they have different advantages, disadvantages, and use cases.&lt;/p&gt;

&lt;p&gt;In this blog, we'll explore &lt;strong&gt;React Native Expo&lt;/strong&gt; and &lt;strong&gt;Bare Bone&lt;/strong&gt; projects, how to get started with each, and when to use one over the other.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Expo?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Expo&lt;/strong&gt; is a framework and platform for React Native that allows developers to build native iOS and Android apps using JavaScript. It simplifies a lot of the underlying setup and offers a rich ecosystem of tools and services.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features of Expo:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Out-of-the-box features:&lt;/strong&gt; It includes a large number of pre-built components, such as camera access, push notifications, and file system management.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Zero build configuration:&lt;/strong&gt; You don’t need to install Android Studio or Xcode to build and test apps. Expo provides a build service that can create the final binaries for both platforms.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Faster development cycle:&lt;/strong&gt; You can preview changes instantly with Expo Go, a mobile app that helps you run your code directly on your device.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Setting Up an Expo Project&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Install Expo CLI:&lt;/strong&gt; First, install the Expo CLI globally on your machine:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g expo-cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2.&lt;strong&gt;Create an Expo Project:&lt;/strong&gt; Use the following command to create a new Expo project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;expo init MyExpoApp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You'll be prompted to choose between different project templates (blank, tab navigation, or managed workflow with TypeScript). Select the one that fits your needs.&lt;/p&gt;

&lt;p&gt;3.&lt;strong&gt;Start the Development Server:&lt;/strong&gt; Navigate into your project folder and run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd MyExpoApp
expo start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can then open the Expo Go app on your iOS or Android device, scan the QR code, and immediately see the app running on your phone. This allows for a fast and efficient development workflow.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Benefits of Expo:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1. &lt;strong&gt;Ease of Use:&lt;/strong&gt; Expo abstracts much of the native complexity, making it easier for beginners to start building mobile apps.&lt;/li&gt;
&lt;li&gt;2. &lt;strong&gt;Cross-Platform Development:&lt;/strong&gt; The same code works on both iOS and Android with minimal adjustments.&lt;/li&gt;
&lt;li&gt;3. &lt;strong&gt;Quick Setup:&lt;/strong&gt; No need to deal with Xcode, Android Studio, or any complex configurations to get started.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Limitations of Expo:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Limited Native Customization:&lt;/strong&gt; If you need to implement custom native modules, Expo might not support them directly unless you "eject" to a bare project.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;App Size:&lt;/strong&gt; Expo apps are generally larger because they include all the native modules, even if you don’t use them.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dependency on Expo:&lt;/strong&gt; You rely on the Expo SDK and updates, which may sometimes limit flexibility in using the latest native features.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What is a Bare Bone React Native Project?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;Bare Bone&lt;/strong&gt; React Native project is a more traditional approach where you have full control over the native code for both Android and iOS. Unlike Expo, a bare project doesn't abstract native configurations, meaning you'll need to manage build tools like Xcode and Android Studio yourself.&lt;/p&gt;

&lt;p&gt;This approach is highly customizable and is ideal when you need direct access to native code or custom libraries.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setting Up a Bare Bone Project&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Install React Native CLI:&lt;/strong&gt; First, ensure you have the React Native CLI installed globally:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g react-native-cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2.&lt;strong&gt;Create a Bare React Native Project:&lt;/strong&gt; You can create a new project using the React Native CLI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx react-native init MyBareApp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3.&lt;strong&gt;Running the App:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For iOS: You need to have Xcode installed. To run the app:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx react-native run-ios
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;For Android: You need Android Studio set up. To run the app:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx react-native run-android
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will build the app natively on your machine and allow you to test it on a simulator or device.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Benefits of a Bare Bone Project:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Full Customization:&lt;/strong&gt; You have full access to native code, which is ideal for apps requiring custom native modules or integrations with native features.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Smaller App Size:&lt;/strong&gt; Since you control which libraries are included, your app can be leaner, including only the native code necessary for your functionality.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;More Flexibility:&lt;/strong&gt; You can install and use any React Native or native library, even if it's not supported by Expo.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Limitations of a Bare Bone Project:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Complex Setup:&lt;/strong&gt; You'll need to manage separate build environments for iOS and Android, which may require tools like Xcode and Android Studio.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Longer Build Times:&lt;/strong&gt; Because you're compiling the code natively, you might experience longer build and iteration times compared to Expo’s hot reload.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;More Maintenance:&lt;/strong&gt; You'll be responsible for updating native dependencies and keeping your project in sync with new versions of React Native.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;When to Use Expo vs. Bare Bone&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Use Expo If:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You want a fast, easy setup with minimal native configuration.&lt;/li&gt;
&lt;li&gt;You're building an MVP (Minimum Viable Product) or a prototype.&lt;/li&gt;
&lt;li&gt;Your app's functionality fits within the native modules provided      by Expo.&lt;/li&gt;
&lt;li&gt;You want to avoid managing native build tools (Xcode, Android      Studio).&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Use a Bare Bone Project If:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You need full access to native APIs and want to integrate custom      native code.&lt;/li&gt;
&lt;li&gt;Your app requires a small footprint and needs to avoid      unnecessary libraries.&lt;/li&gt;
&lt;li&gt;You plan to maintain the app long-term and need full control      over dependencies.&lt;/li&gt;
&lt;li&gt;You’re working on an enterprise-level app with specific custom      requirements.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ejecting from Expo&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you start with Expo and eventually need more control over native code, Expo provides an option to "eject" to a bare React Native project.&lt;/p&gt;

&lt;p&gt;Run the following command to eject:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;expo eject
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will give you access to native code but will also require you to manage native dependencies moving forward, like any other bare React Native project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Choosing between &lt;strong&gt;Expo&lt;/strong&gt; and a &lt;strong&gt;Bare Bone&lt;/strong&gt; React Native project depends on your app's requirements and your familiarity with native development tools. Expo is perfect for quickly starting a project with a great development experience and lots of pre-built functionality, while a bare project gives you full control over the native code and app customization.&lt;/p&gt;

&lt;p&gt;When starting your next React Native project, consider your specific needs—Expo for simplicity and quick setup, or a bare project for flexibility and long-term customization. Both approaches are valid, and each shines in different scenarios.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Happy coding with React Native!&lt;/strong&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to Create a React Native SDK: A Comprehensive Guide</title>
      <dc:creator>Himanshu Sharma</dc:creator>
      <pubDate>Thu, 26 Sep 2024 13:15:36 +0000</pubDate>
      <link>https://dev.to/himanshu_sharma_747c6d9d5/how-to-create-a-react-native-sdk-a-comprehensive-guide-2amp</link>
      <guid>https://dev.to/himanshu_sharma_747c6d9d5/how-to-create-a-react-native-sdk-a-comprehensive-guide-2amp</guid>
      <description>&lt;p&gt;React Native is a popular framework for building mobile applications, combining the best parts of native development with the flexibility of React. As React Native grows in popularity, the need for reusable libraries or SDKs (Software Development Kits) becomes important for developers looking to share functionality across multiple applications. In this blog, we'll explore the steps involved in creating a React Native SDK, from setting up the project to distributing it for others to use.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Create an SDK for React Native?&lt;/strong&gt;&lt;br&gt;
An SDK allows developers to encapsulate functionality into reusable packages that can be shared across multiple applications. This reduces redundancy and ensures that updates or changes to core logic can be implemented across all applications seamlessly. Use cases for React Native SDKs include:&lt;/p&gt;

&lt;p&gt;Handling payments&lt;br&gt;
Implementing analytics and tracking&lt;br&gt;
Managing authentication&lt;br&gt;
Abstracting complex business logic or UI components&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Steps to Create a React Native SDK&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Set Up the Project&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Before you can create an SDK, you need to set up a React Native project that will serve as the foundation for your SDK.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.1. Install React Native CLI&lt;/strong&gt;&lt;br&gt;
First, ensure that you have React Native CLI installed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g react-native-cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;1.2. Create a New React Native Project&lt;/strong&gt;&lt;br&gt;
Create a new project where you’ll develop your SDK:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx react-native init MySDK
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Navigate to your project directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd MySDK
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Setup TypeScript (Optional but Recommended)&lt;/strong&gt;&lt;br&gt;
TypeScript helps with type safety and improves the development experience. To add TypeScript to your React Native SDK:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save-dev typescript @types/react @types/react-native
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then rename your .js files to .ts or .tsx and create a tsconfig.json file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "strict": true,
    "jsx": "react-native",
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true
  },
  "exclude": ["node_modules"]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Create Reusable Modules&lt;/strong&gt;&lt;br&gt;
The core of your SDK will be reusable components or modules. Depending on what functionality your SDK provides, you may need to create native modules (for Android/iOS) or JavaScript components.&lt;br&gt;
&lt;strong&gt;3.1. Create a Native Module&lt;/strong&gt;&lt;br&gt;
React Native allows you to write native code for Android and iOS that interacts with JavaScript. Let’s create a simple native module.&lt;/p&gt;

&lt;p&gt;iOS&lt;br&gt;
Create a new Objective-C or Swift file in the ios/ directory (for this example, we’ll use Objective-C):&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to ios/MySDK and add a new file called MyModule.m:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#import "React/RCTBridgeModule.h"

@interface RCT_EXTERN_MODULE(MyModule, NSObject)
RCT_EXTERN_METHOD(sayHello:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
@end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;2.In MyModule.swift, implement the native functionality:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@objc(MyModule)
class MyModule: NSObject {
  @objc
  func sayHello(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
    resolve("Hello from iOS Native Module!")
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For Android, you will create a new Java/Kotlin module:&lt;/p&gt;

&lt;p&gt;1.Create a new file under android/app/src/main/java/com/mysdk/ called MyModule.java:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package com.mysdk;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Promise;

public class MyModule extends ReactContextBaseJavaModule {

    public MyModule(ReactApplicationContext reactContext) {
        super(reactContext);
    }

    @Override
    public String getName() {
        return "MyModule";
    }

    @ReactMethod
    public void sayHello(Promise promise) {
        promise.resolve("Hello from Android Native Module!");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3.2. Export Native Modules to JavaScript&lt;/strong&gt;&lt;br&gt;
You’ll need to bridge your native code to JavaScript.&lt;/p&gt;

&lt;p&gt;In index.js, export the native module like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { NativeModules } from 'react-native';

const { MyModule } = NativeModules;

export const sayHello = async () =&amp;gt; {
  try {
    const message = await MyModule.sayHello();
    return message;
  } catch (error) {
    console.error(error);
  }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Create JavaScript Components&lt;/strong&gt;&lt;br&gt;
Not all functionality in your SDK needs to be written in native code. You can also create pure JavaScript components or hooks.&lt;/p&gt;

&lt;p&gt;Here’s an example of a simple reusable button component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import { TouchableOpacity, Text, StyleSheet } from 'react-native';

const MyButton = ({ title, onPress }) =&amp;gt; {
  return (
    &amp;lt;TouchableOpacity style={styles.button} onPress={onPress}&amp;gt;
      &amp;lt;Text style={styles.text}&amp;gt;{title}&amp;lt;/Text&amp;gt;
    &amp;lt;/TouchableOpacity&amp;gt;
  );
};

const styles = StyleSheet.create({
  button: {
    backgroundColor: '#007BFF',
    padding: 10,
    borderRadius: 5,
  },
  text: {
    color: '#fff',
    textAlign: 'center',
  },
});

export default MyButton;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. Publish Your SDK&lt;/strong&gt;&lt;br&gt;
Once your SDK is ready, it’s time to package and distribute it. You can publish it to npm so other developers can install and use it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5.1. Prepare for Publishing&lt;/strong&gt;&lt;br&gt;
Update your package.json to include the necessary information:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "my-react-native-sdk",
  "version": "1.0.0",
  "main": "index.js",
  "react-native": "index.js",
  "author": "Your Name",
  "license": "MIT"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure your .npmignore file excludes unnecessary files like build artifacts and node_modules.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5.2. Publish to npm&lt;/strong&gt;&lt;br&gt;
To publish your SDK, first login to npm:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then publish your package:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm publish
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5.3. Install in Another Project&lt;/strong&gt;&lt;br&gt;
Once published, your SDK can be installed in any React Native project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install my-react-native-sdk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Developers can then use it in their applications:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { sayHello } from 'my-react-native-sdk';

const App = () =&amp;gt; {
  useEffect(() =&amp;gt; {
    sayHello().then(message =&amp;gt; console.log(message));
  }, []);

  return &amp;lt;Text&amp;gt;Check the console for the message!&amp;lt;/Text&amp;gt;;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6. Testing and Documentation&lt;/strong&gt;&lt;br&gt;
Testing your SDK across different environments (iOS, Android) is crucial. Use a combination of manual testing and automated tests (e.g., Jest, Detox) to ensure it works as expected.&lt;/p&gt;

&lt;p&gt;In addition, providing comprehensive documentation is key to making your SDK easy for others to use. Document your SDK features, APIs, and provide examples.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Creating a React Native SDK involves setting up reusable components or modules that can be shared across multiple applications. By combining native code with JavaScript components, you can create a flexible and powerful SDK that serves different needs.&lt;/p&gt;

&lt;p&gt;Whether you're creating a payment gateway SDK, analytics tool, or authentication system, following the steps outlined in this blog will help you build and distribute a React Native SDK effectively.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
