React Native Questions
Warm up for your React Native interview with most asked questions and answers for junior, mid, and senior roles.
What are refs and why are they useful?
Show AnswerHide Answer
Refs provide a way to access a DOM node or component instance from within a component. In React, you can create a reference using useRef() hook.
What are some ways to add style to a react native component?
Show AnswerHide Answer
- Inline styling
- StyleSheet
- Styled Components
- Tailwind
What are components?
Show AnswerHide Answer
Components are independent and reusable bits of code. They serve the same purpose as JavaScript functions
What is justifyContent and alignItems in React Native?
Show AnswerHide Answer
justifyContent is used to align the content on the main axis. alignItems is used to align the content on the cross axis.
When flexDirection: "row", Main Axis is left to right
When flexDirection: "column", Main Axis is top to bottom
When should you use Flatlist or ScrollView?
Show AnswerHide Answer
Use Flatlist when:
- A big list of similar items
- A list of items that you don't know the length
Use Scrollview when:
- A small list of items
- Generic items in a scrollable area
What is JSX?
Show AnswerHide Answer
JSX is an HTML like syntax used by React and React Native that allows you to write HTML inside of JavaScript.
What are props in React Native?
Show AnswerHide Answer
Props can be simply the component properties or pieces of data that are passed to the component.
What are native apps?
Show AnswerHide Answer
- A native app is an app that is developed for use on a specific platform.
- For example Swift and Objective-C for native iOS apps and Java and Kotling for Android native apps.
What is React Native
Show AnswerHide Answer
React Native is an open-source mobile application framework created by Facebook.
It is used to develop applications for Android, iOS, Web, and UWP by enabling developers to use React and native platform capabilities.
What are some benefits of using React Native?
Show AnswerHide Answer
- Code Reusability and Cross-platform compatibility
- Native Look and Feel
- Large Community Support
- Live/ Hot Reloading
- Great Performance
- Open-source framework
What are some ways to persist data in React Native?
Show AnswerHide Answer
- Async Storage
- SQLite
- Realm DB
- Watermelon DB
- MMKV
Explain some of the tradeoffs between building a React Native and building a “true” native app.
Show AnswerHide Answer
If you are building an app that depends a lot on native libraries, you may want to consider building a Native app, because native provides superior performance and gives developers complete access to the capabilities of each device. But you will have two codebases for your app, one for Android and one for iOS.
On the other hand, if your application does not depends a lot on native libraries, you may want to build a React Native app, because it is easier to maintain and it is easier to test.
What is the difference between React Native and ReactJS?
Show AnswerHide Answer
- ReactJS main focus is Web Development
- ReactJS is a Javascript library
- React uses HTML tags like p,span,div, etc...
- React Native is focused on Mobile Development
- React Native is a mobile framework that uses Javascript Engine
- Both are open-source and supports the JSX syntax
What is State in React Native?
Show AnswerHide Answer
State is a mutable data structure that is used to contain data about a component. A component's state can change over time; whenever it changes, the component re-renders
How are props and state different?
Show AnswerHide Answer
Props are immutable. State is mutable.
How are Hot Reloading and Live Reloading in React Native different?
Show AnswerHide Answer
Hot Reloading
- It only reloads the file that changed
- The state of your app is maintained.
- Modify your code without any delay.
Live Reloading
- It reloads the whole app.
- The state of your app is reseted.
What is AppRegistry?
Show AnswerHide Answer
AppRegistry is the entry point to your React Native application. It is like the root component of your application.
What does StyleSheet.create do and why is it useful?
Show AnswerHide Answer
StyleSheet.create is used to create a stylesheet object that you can use to style your components.
It's useful because moving your styles to a stylesheet object makes it easier to manage, reuse styles, and improve performance.
What is AsyncStorage?
Show AnswerHide Answer
AsyncStorage is a simple, unencrypted, asynchronous, persistent, key-value storage system that is global to the app.
List some packages that implement native modules for both iOS and Android
Show AnswerHide Answer
- Camera
- Bluetooth
- Contacts
- Date Picker
- Image Picker
List some ways you can optimize an application
Show AnswerHide Answer
- Use FlatLIst or SectionList to render large lists.
- Remove console statements
- Memoize expensive computations (memo HOC, useCallback and useMemo)
- Cache image locally
- Use WebP image format
- Use Native driver with Animated API
- Use Hermes and ProGuard
What is props drilling?
Show AnswerHide Answer
Prop drilling is the term for passing data through several nested children components. It can cause issues with component reusability and app performance.
How do you handle different screen sizes in React Native?
Show AnswerHide Answer
You can use PixelRatio which gives you access to the device's pixel density and font scale, so you can use it to handle different screen sizes, but there is a couple of libraries that provide some tools to handle responsiveness, like:
- react-native-responsive-screen
- react-native-responsive-fontsize
- react-native-auto-size-text
What are hooks in React Native and what are some of the advantages?
Show AnswerHide Answer
Hooks allow you to write functions that can be used in React components. They are a way to write code in a modular and reusable way, using all the React features.
What are Container/Smart components?
Show AnswerHide Answer
Container components are the ones that manage the state of the application. They receive the props and pass them to the presentational components.
What are Presentational/Dumb Components?
Show AnswerHide Answer
Presentational components are the ones that receive the props and render the UI. They don't manage or change the state of the application.
How useEffect works in React Native?
Show AnswerHide Answer
It is a hook that is called after the component is rendered for the first time, before the component is unmounted, and also when some of the props in the dependency array changes.
What is the significance of keys in React Native?
Show AnswerHide Answer
It helps React identify which items have changed, added, or removed, increasing its performance when diffing between the virtual and real DOM
How to use animations in React Native?
Show AnswerHide Answer
You can implement animations in React Native using the Animated API or react-native-reanimated library
What is Redux and why it is used?
Show AnswerHide Answer
Redux is a state management pattern. It helps you manage the application state, synchronizing the application's state between multiple parts of the application.
It has three main parts:
- Reducers: A function that returns the next state given the current state and an action to handle.
- Actions: An object that describes an event. It has a type property that defines the event, and a payload property that contains the data associated with the event.
- Store: A single source of truth for the application state. It is the only source of truth for the application state.
How to use SVG in React Native?
Show AnswerHide Answer
You can use SVG in React Native using the react-native-svg library
What is Expo?
Show AnswerHide Answer
Expo is a platform for building native apps for iOS and Android. It provides a set of tools that simplify the development of React Native apps.
How do you debug React Native apps?
Show AnswerHide Answer
You can use Chrome Dev Tools, react-native-debugger, Flipper or Reactotron to debug React Native apps.
What is the difference between a functional component and a class component?
Show AnswerHide Answer
A functional component is a function that returns a React element. A class component is a class that extends React.Component.
What is the difference between useState and useReducer?
Show AnswerHide Answer
useState is a hook that allows you to manage the state of a component. It is a function that returns an array with two elements: the current state and a function to update the state, and it uses useReducer under the hood.
useReducer gives you more control over the state of your component. It takes a reducer function and initial state as arguments and returns the state and dispatch method.
What is Gesture Responder System?
Show AnswerHide Answer
The gesture responder system manages the lifecycle of gestures in your app. A touch can go through several phases as the app determines what the user's intention is.
For example, the app needs to determine if the touch is scrolling, sliding on a widget, or tapping. This can even change during the duration of a touch. There can also be multiple simultaneous touches.
How many threads run in a React Native app?
Show AnswerHide Answer
We can say there are three threads that mainly run a React Native app:
- UI thread — this is the native thread used to run Swift/Objective C on iOS devices and Java/Kotlin on Android devices, an application’s UI is manipulated solely on this thread. Here the application’s Views are rendered and users of the app can interact with the OS.
- JavaScript thread — this is the thread that executes JavaScript separately via a Javascript Engine. An application’s logic – including which Views to display and in what manner they are displayed.
What is Flux?
Show AnswerHide Answer
Flux is an architecture for creating data layers in JavaScript applications. It was designed on Facebook along with the React view library.
It places a focus on creating explicit and understandable update paths for your application's data, which makes tracing changes during development simpler and makes bugs easier to track down and fix.
What are some concepts about React Native life-cycle?
Show AnswerHide Answer
React Native has a lifecycle of three stages:
- Mounting
- Updating
- Unmounting
Mounting is the process of creating a native view and mounting it to the screen.
Updating is the process of updating the native view.
Unmounting is the process of removing the native view from the screen.
With React Hooks we can use useEffect and useState to manipulate and trigger these stages
What JavaScript engine does React native use?
Show AnswerHide Answer
On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore.
What is and when should you use useMemo?
Show AnswerHide Answer
useMemo is a React hook that allows you to memoize the return of expensive functions, avoiding calling them on every render.
What is and when should you use useCallback?
Show AnswerHide Answer
useCallback is a React hook that returns a memoized version of the callback that only changes if one of the dependencies has changed.
It's useful when you have a component in which the child is re-rendering too often, so the function object returned from useCallback
will be the same between re-renders.
What is and when should you use memo (HOC)?
Show AnswerHide Answer
memo is a React High Order Component that will cause React to skip rendering a component if its props have not changed.
What happens when you call setState
Show AnswerHide Answer
- React will merge the object that will pass in setState to the current state of the component
- The reconciliation process will start.
- React will construct a new tree of React Elements with your changes (Virtual DOM)
- React will diff this new tree with the previous element tree (Real DOM)
- By doing this the UI will be re-rendered by only making updates where absolutely necessary.
What is meant by InteractionManager, and why it is Important?
Show AnswerHide Answer
InteractionManager allows long-running work to be scheduled after any interactions/animations have completed. In particular, this allows JavaScript animations to run smoothly.
Explain the Flow of Redux
Show AnswerHide Answer
Redux follows the unidirectional data flow.
So, an action is dispatched to the store's reducer along with the current state of the store. The reducer then returns a new state based on the action. The new state is then passed to the store's subscribers.
What is Component Driven Development (CDD)?
Show AnswerHide Answer
Component-Driven Development (CDD) is a development methodology that anchors the build process around components.
It is a process that builds UIs from the “bottom-up” by starting at the level of components and ending at the level of pages or screens.
What is the difference between ShadowDOM and VirtualDOM?
Show AnswerHide Answer
Virtual DOM is a copy of the whole DOM object.
On the other hand, Shadow DOM creates small pieces of the DOM object which has isolated scope for the element they represent.
What is Higher Order Component or HOC?
Show AnswerHide Answer
A higher-order component transforms a component into another component.
A HOC composes the original component by wrapping it in a container component. A HOC is a pure function with zero side effects.
List some concepts about React Native Architecure?
Show AnswerHide Answer
Old Architecture
- The JavaScript thread.
- The Native/UI thread.
- The bridge.
New Architecture
- The bridge will be replaced by JSI
- Ability to swap the JavaScriptCore with other Engines
- Complete Interoperability between all threads
- Web-like Rendering system
- Time-sensitive tasks can be executed synchronously
- Lazy Loading of Turbo Modules
- Static Type Checking for compatibility between JS and Native Side
What is React Native Bridge?
Show AnswerHide Answer
The Bridge in React Native is the layer that handles the interaction between JavaScript and the Native modules.
It is primarily a carrier layer that conducts asynchronously grouped feedback messages from JavaScript to Native modules.
What is Fabric in React Native?
Show AnswerHide Answer
Fabric is React Native's new rendering system, conceptual evolution of the legacy render system.
The core principles are to unify more render logic in C++, improve interoperability with host platforms, and 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.
What is OTA (Over the air updates)?
Show AnswerHide Answer
Over the Air updates are updates that are downloaded directly to the device, OTA allows us to send updated Javascript bundles directly to users.
Does React Native have a Virtual DOM?
Show AnswerHide Answer
Yes, React-Native creates a tree hierarchy to define the initial layout and creates a diff of that tree on each layout change to optimize the renderings.
But React Native manages the UI updates through couple of architecture layers that in the end translate how views should be rendered while trying to optimize the changes to a minimum in order to deliver the fastest rendering possible.