CodeBlanks Logo Icon CodeBlanks

Summary - New architecture

Combine JSI, Fabric and TurboModules to write a new architecture summary.

Summary - New architecture

The new architecture rests on three pillars: JSI (direct C++ binding), Fabric (new render layer) and TurboModules (lazy native modules). Codegen produces the native skeleton for them.

The bridge goes away; serialization disappears; synchronous calls become possible. Fabric works with React 18 concurrent rendering. The new architecture is on by default from React Native 0.74.

Practice Write the TurboModule call

Fetch the Math TurboModule with TurboModuleRegistry.getEnforcing. Pass Spec as the generic. Assign the result to MathModule.

Starter code

App.js
import { TurboModuleRegistry } from 'react-native';
import type { Spec } from './NativeMath';

// Fetch the module here

export default MathModule;

Sample solution

App.js
import { TurboModuleRegistry } from 'react-native';
import type { Spec } from './NativeMath';

const MathModule = TurboModuleRegistry.getEnforcing<Spec>('Math');

export default MathModule;

Practice Export the Fabric native component

Define a Fabric native component named Box with a NativeProps interface. Use codegenNativeComponent; default export it.

Starter code

App.js
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';

interface NativeProps {
  color?: string;
}

// Define and export the Box component here

Sample solution

App.js
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';

interface NativeProps {
  color?: string;
}

const Box = codegenNativeComponent<NativeProps>('Box');
export default Box;

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What are the pillars of the new architecture?

  • Bridge, Async, JSON
  • JSI, Fabric, TurboModules Correct answer
  • CSS, HTML, DOM
  • Webpack, Babel, ESLint

Explanation: The three pillars are JSI, Fabric and TurboModules.

2 Match all the pieces

Term Meaning
JSI Direct C++ binding
Fabric Render layer
TurboModules Lazy modules
Codegen Skeleton generator

All lessons in Expert