React is a JS library whichthat is used to make beautiful, flexible, performant single page web applications, So now a question will appear in your mind what is single page web app.?
A single-page application is an app that works inside a browser and does not require page reloading during use. You are using these types of applications every day. These are, for instance: Gmail, Google Maps, Facebook, or GitHub. SPAs are all about serving an outstanding UX by trying to imitate a “natural” environment in the browser — no page reloads, no extra wait time. It is just one web page that you visit which then loads all other content using JavaScript — which they heavily depend on. SPA requests the markup and data independently and renders pages straight in the browser. We can do this thanks to advanced JavaScript frameworks like AngularJS, Ember.js, Meteor.js, Knockout.js, React.js, and Vue.js. Single-page sites help keep the user in one, comfortable web space where content is presented to the user in a simple, easy, and workable fashion.
All of the React code is executed inside the JS thread and the final value passes to the native thread which draws a layout on the screen with the final value.
JS thread performs all of the calculations and passes data to the native, How?
React uses an Async Bridge to pass data to a Native thread in JSON format is called React-Native
NOTE: New architecture does not rely on the bridges anymore it used JSI and fabric for the communication between native and JS code which happened synchronously(it's explained in the below section).
So we use Native components for making a presentational view in react-native and use that bridge to communicate between these two different worlds.
Update: React-Native is now going through a re-architecuterarchitecture phase and facebookthe Facebook team is trying to remove the async bridge to communicate between JS and native synchronously the major part of this re-architecuterarchitecture is JSI(Javascript interface) and fabircfabric.
JSI: JSI removes the need for a bridge between Native(Java/ObjC) and Javascript code. It also removes the requirement to serialize/deserialize all the information as JSON for communication between the two worlds. JSI is opening doors to new possibilities by bringing closesclose the javascript and the native worlds.
Below are the main things which JSI is offers.
Javascript Interface which allows us to register methods with the Javascript runtime. These methods are available via the global object in the Javascript world.
The methods can be entirely written in C++ or they can be a way to communicate with Objective C code on iOS and Java code in Android.
Any native module that is currently using the traditional bridge for communication between Javascript and the native worlds can be converted to a JSI module by writing a simple layer in C++ On iOS writing, this layer is simple because C++ can run directly in Objective C hence all the iOS frameworks and code is available to use directly.
On android however we have to go anthe extra mile to do this through JNI.
These methods can be fully synchronous which means using async/await is not mandatory.
Fabric: FabircFabric is a new UI layer whichthat allows us to communicate with the native UI components synchronoussynchronously, According to the docs.
Fabric is React Native's new rendering system, a conceptual evolution of the legacy render system. The core principles are to unify more render logic in C++, improve interoperability with host platforms, and to unlock new capabilities for React Native. Development began in 2018 and in 2021, React Native in the Facebook app is backed by the new renderer.