React Native's Two Threads: JS and UI
React Native splits work between a JS thread for React logic and a UI thread for drawing pixels, keeping the app responsive. The JS thread runs your code and calculates layout, while the UI thread handles native view updates.
Why it exists
To prevent long-running JavaScript code from blocking the main UI thread, which would make an application feel frozen and unresponsive. By separating UI manipulation from business logic, React Native can ensure smooth animations and interactions even while React is busy calculating the next state.
The mental model
Think of it as a restaurant with a kitchen and a front-of-house. The JS thread is the kitchen, preparing the "order" by running React code and calculating the next UI state and layout. The UI thread is the front-of-house, delivering the finished dish to the customer by drawing pixels on the screen. They work in parallel, but only the front-of-house staff can interact directly with the customer (the screen).
How it works
React Native's renderer uses two primary threads. The JavaScript thread executes your React code, runs the render phase, and calculates layout. The UI thread, often called the main thread, is the only thread that can create and update the native host views. The framework guarantees thread safety by using immutable data structures. Instead of modifying data in place, every update creates new objects, allowing for safe communication and synchronous APIs between the threads.
When to use it
This model is fundamental to all React Native apps; you don't choose to use it, but you must understand it to build performant apps. For example, when a user taps a button (a high-priority event), React Native can interrupt a render happening on the JS thread and execute the update synchronously on the UI thread for immediate feedback. For lower-priority events like scrolling, the render continues on the JS thread without blocking user interaction.
When not to use it
The main footgun is misunderstanding the separation. Never perform long-running, synchronous tasks on the JS thread, as this will block React's entire render cycle and prevent the UI from updating, making the app unresponsive. Offload heavy computations to native modules or use dedicated worker threads if necessary. The UI thread must be kept free to handle user interactions and animations.
One canonical example
A user is scrolling a long list. While they scroll, React is busy rendering new list items on the JS thread. If the user suddenly taps a "Like" button (a discrete, high-priority event), React Native can pause the list rendering, run the "Like" button's state update and render synchronously on the UI thread to provide instant visual feedback, and then resume rendering the rest of the list on the JS thread.
Interview question
What is the primary advantage of React Native's architecture that separates the JavaScript thread from the UI thread?
- a.It enables the use of mutable data structures for efficient, in-place updates between threads.
- b.It simplifies the process of debugging by isolating all UI-related logic to a single thread.
- c.It allows JavaScript to directly manipulate native UI elements without a bridge.
- d.It ensures that the application's user interface remains responsive even during intensive JavaScript computations.Correct
Why? this is the answer
The core purpose of the two-thread architecture is to prevent the UI from freezing when the JavaScript thread is busy, ensuring a smooth user experience. JavaScript does not directly manipulate native UI components; it prepares instructions that the UI thread then executes to update native views.
Just read this? Test yourself on what you have been reading.
Read the original → reactnative.dev
- #react native
- #performance
- #threading
- #architecture
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on react native — each one lists the topics its interview covers.
See open roles