React Native Interview Questions – Set 01

How many threads run in React Native?

The React Native app contains the following thread:

  • React Native UI Thread (Main Thread): This thread is used for the layout of the mobile app.
  • React Native JavaScript Thread: It is a thread where our business logic will run. It means JS thread is a place where our JavaScript code is executed.
  • React Native Modules Thread: Sometimes, our app needs access to platform API, which happens as a part of native module thread.
  • React Native Render Thread: This thread is used to generate actual OpenGL commands used to draw the app UI.

Can we combine native iOS or Android code in React Native?

Yes, we can combine the native iOS or Android code with React Native. It can combine the components written in Objective-C, Java, and Shift.

What are states in React Native?

It is used to control the components. The variable data can be stored in the state. It is mutable means a state can change the value at any time.

Example

Here, we are going to create a Text component with state data. The content of the Text component will be updated whenever we click on it. The event onPress calls the setState function, which updates the state with “myState” text.

import React, {Component} from ‘react’;
import { Text, View } from ‘react-native’;

export default class App extends Component {
state = {
myState: ‘This is a text component, created using state data. It will change or updated on clicking it.’
}
updateState = () => this.setState({myState: ‘The state is updated’})
render() {
return (

{this.state.myState}

);
}
}

Can you integrate more features in the existing app by React Native?

Yes, we can add new features to existing applications in React Native.

Why React Native app use keys?

Keys are a unique identifier. They are used to identify which items have changed, updated, or deleted from the lists. It should always use inside the array.

How to use Axios in the React Native?

Axios is a popular library for making HTTP requests from the browser. It allows us to make GET, POST, PUT, and DELETE requests from the browser. Therefore, React Native uses Axios to make requests to an API, return data from the API, and then perform actions with that data in our React Native app. We can use Axios by adding the Axios plugin to our project using the following command.

# Yarn
$ yarn add axios

# npm
$ npm install axios –save
Axios have several features, which are listed below:

  • It makes XMLHttpRequests from the browser.
  • It makes Http requests from the React Native framework.
  • It supports most of the React Native API.
  • It offers a client-side feature that protects the application from XSRF.
  • It automatically transforms response and request data with the browser.

What is ListView?

ListView is a core component of React Native, which contains a list of items and displays in vertical scrollable lists.

For what XHR Module is used in the React Native?

In React Native, the XHR module is used to implement the XMLHttpRequest. It is an object for interacting with remote services. This object is consists of two parts, front-end and back-end, where the front-end allows interacting within JavaScript. It sends the request to the XHR back-end, which is responsible for a processing network request. The back-end part is called Networking.

What is React Native Apps?

React Native Apps are not web applications. These types of apps are running on mobile devices, and cannot load over the browser. Also, they are not hybrid apps that build over Ionic, Phonegap, etc. which can run over WebView component. They are the real native apps built in a single language JavaScript with the native components to run on mobile devices.

Do we use the same code base for Android and iOS?

Yes, we can use the same codebase for Android and iOS, and React takes care of all the native component translations. For example, a React Native ScrollView use ScrollView on Android and UiScrollView on iOS.