Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

List down Key Points to integrate React Native in an existing Android mobile application

Answer»

Primary points to note to integrating React Native COMPONENTS into your Android application are to:

  • Set up React Native dependencies and DIRECTORY structure.
  • Develop your React Native components in JavaScript.
  • Add a ReactRootView to your Android APP. This view will SERVE as the container for your React Native component.
  • Start the React Native server and run your native application.
  • Lastly, we need to VERIFY that the React Native aspect of your application works as expected.
2.

Describing Networking in React Native and how to make AJAX network calls in React Native?

Answer»

React Native provides the Fetch API for networking needs. 
To fetch content from an arbitrary URL, we can pass the URL to fetch:

fetch('https://mywebsite.com/endpoint/', { METHOD: 'POST', headers: { Accept: 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({ firstParam: 'yourValue', secondParam: 'yourOtherValue' })});

Networking is an inherently ASYNCHRONOUS operation. Fetch methods will return a Promise that makes it straightforward to write CODE that works in an asynchronous manner:

const getMoviesFromApi = () => { return fetch('https://reactnative.dev/movies.json') .then((response) => response.json()) .then((json) => { return json.movies; }) .catch((error) => { console.error(error); });};

The XMLHttpRequest API is built in to React Native  Since frisbee and Axios use XMLHttpRequest we can even use these libraries.

var request = NEW XMLHttpRequest();request.onreadystatechange = (e) => { if (request.readyState !== 4) { return; } if (request.status === 200) { console.log('success', request.responseText); } else { console.warn('error'); }};request.open('GET', 'https://mywebsite.com/endpoint/');request.send();
3.

What is Props Drilling and how can we avoid it ?

Answer»

PROPS Drilling (Threading) is a concept that refers to the process you pass the DATA from the parent component to the exact child Component BUT in between, other COMPONENTS owning the props just to pass it down the chain.

Steps to avoid it

1. React Context API.
2. Composition
3. Render props
4. HOC
5. REDUX or MobX

4.

How to debug React Native Applications and Name the Tools used for it ?

Answer»

In the React Native world, debugging may be done in different ways and with different tools, since React Native is composed of different environments (iOS and Android), which means there’s an assortment of problems and a variety of tools needed for debugging.

  • The Developer Menu:

    Reload: reloads the app
    Debug JS Remotely: opens a channel to a JavaScript debugger
    Enable Live Reload: makes the app reload automatically on clicking Save
    Enable Hot Reloading: watches for changes accrued in a changed file
    Toggle Inspector: toggles an inspector interface, which allows us to inspect any UI element on the screen and its properties, and presents an interface that has other tabs like networking, which shows us the HTTP calls, and a tab for performance.
  • Chrome’s DevTools:

    Chrome is possibly the first tool to think of for debugging React Native. It’s common to use Chrome’s DevTools to debug web apps, but we can also use them to debug React Native since it’s powered by JavaScript.To use Chrome’s DevTools with React Native, first make sure to connect to the same Wi-Fi, then press command + R if you’re using macOS, or Ctrl + M on Windows/Linux. In the developer menu, choose Debug Js Remotely. This will open the DEFAULT JS debugger.
     
  • React Developer Tools
    For Debugging React Native using React’s Developer Tools, you need to use the desktop app. In can installed it globally or locally in your project by just running the following command:
    yarn add react-devtools
    Or NPM:
    npm install react-devtools --save

    React’s Developer Tools may be the best tool for debugging React Native for these two reasons:
    It allows for debugging React components.
    There is also a possibility to debug styles in React Native. There is also a new version that comes with this feature that also WORKS with the inspector in the developer menu. Previously, it was a problem to WRITE styles and have to wait for the app to reload to see the changes. Now we can debug and implement style properties and see the effect of the change instantly without reloading the app.
     
  • React Native Debugger
    While using Redux in your React Native app, React Native Debugger is probably the right debugger for you. This is a standalone desktop app that works on macOS, Windows, and Linux. It even integrates both Redux’s DevTools and React’s Developer Tools in ONE app so you don’t have to work with two separate apps for debugging.
     

React Native CLI

You can use the React Native CLI to do some debugging as well. It can also be used for showing the logs of the app. Hitting react-native log-android will show you the logs of db logcat on Android, and to view the logs in iOS you can run react-native log-ios, and with console.log you can dispatch logs to the terminal:

console.log("some error🛑")
5.

Describe Timers in React Native Application ?

Answer»

Timers are an important and integral part of any application and React Native implements the browser timers.

Timers
 

  • setTimeout, clearTimeout

There may be business requirements to EXECUTE a certain PIECE of code after waiting for some time duration or after a delay setTimeout can be used in such cases, clearTimeout is simply used to CLEAR the timer that is started.

setTimeout(() => {yourFunction();}, 3000);
  • setInterval, clearInterval

setInterval is a method that calls a function or runs some code after specific intervals of time, as specified through the second parameter.

setInterval(() => {console.log('INTERVAL triggered');}, 1000);

A function or block of code that is bound to an interval EXECUTES until it is stopped. To stop an interval, we can use the clearInterval() method.

  • setImmediate, clearImmediate

Calling the function or execution as soon as possible.

var immediateID = setImmediate(function);// The below code displays the alert dialog immediately.var immediateId = setImmediate( () => { alert('Immediate Alert');}

clearImmediate  is used for Canceling the immediate actions that were set by setImmediate().

  • requestAnimationFrame, cancelAnimationFrame

It is the standard way to perform animations.

Calling a function to update an animation before the next animation frame.

var requestID = requestAnimationFrame(function);// The following code performs the animation.var requestId = requestAnimationFrame( () => { // animate something})

cancelAnimationFrame is used for Canceling the function that was set by requestAnimationFrame().

6.

What is Redux in React Native and give important components of Redux used in React Native app ?

Answer»

Redux is a predictable state container for JavaScript apps. It helps write applications that run in different environments. This means the entire data flow of the app is handled WITHIN a SINGLE container while persisting previous state.

Actions: are payloads of information that send data from your application to your store. They are the only source of information for the store. This means if any state change is necessary the change required will be DISPATCHED through the actions.

Reducers: “Actions describe the fact that something happened, but don’t specify how the application’s state changes in response. This is the JOB of reducers.” when an ACTION is dispatched for state change its the reducers duty to make the necessary changes to the state and return the new state of the application.

Store: a store can be created with help of reducers which holds the entire state of the application. The recommended way is to use a single store for the entire application rather than having multiple stores which will violate the use of redux which only has a single store.

Components: this is where the UI of the application is kept.

7.

What is State and how is it used in React Native?

Answer»

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.

import React, {Component} from 'react'; import { Text, View } from 'react-native'; export default class App extends Component { state = { myState: 'State of Text Component' }updateState = () =&GT; this.setState({myState: 'The state is updated'})RENDER() {return (<View> <Text onPress={this.updateState}> {this.state.myState} </Text> </View> ); } }

Here we create a Text component with state data. The content of the Text component will be updated whenever we CLICK on it. The state is updated by event onPress .

8.

How is user Input Handled in React Native ?

Answer»

TextInput is a Core Component that allows the user to enter text. It has an onChangeText prop that takes a function to be called every TIME the text CHANGES, and an onSubmitEditing prop that takes a function to be called when the text is submitted.

import REACT, { useState } from 'react';import { Text, TextInput, View } from 'react-native';const PizzaTranslator = () => { const [text, setText] = useState(''); return ( <View STYLE={{padding: 10}}> <TextInput style={{height: 40}} placeholder="Type here to TRANSLATE!" onChangeText={text => setText(text)} defaultValue={text} /> <Text style={{padding: 10, fontSize: 42}}> {text.split(' ').map((word) => word && '🍕').join(' ')} </Text> </View> );}export default PizzaTranslator;
9.

Are default props available in React Native and if yes for what are they used and how are they used ?

Answer»

Yes, default props available in REACT Native as they are for React,  If for an INSTANCE we do not pass props value, the component will use the default props value.

import React, {Component} from 'react';

import {View, TEXT} from 'react-native';class DefaultPropComponent EXTENDS Component { render() { return ( <View> <Text> {this.props.NAME} </Text> </View> ) }}Demo.defaultProps = { name: 'BOB'}export default DefaultPropComponent;
10.

What are threads in General ? and explain Different Threads in ReactNative with Use of Each ?

Answer»

The single sequential flow of control within a program can be controlled by a thread.

React Native right now uses 3 threads:

  • MAIN/UI  Thread — This is the main application thread on which your Android/iOS app is RUNNING. The UI of the application can be CHANGED by the Main thread and it has ACCESS to it .
     
  • Shadow Thread — layout created using React library in React Native can be CALCULATED by this and it is a background thread.
     
  • JavaScript Thread — The main Javascript code is executed by this thread.
11.

Describe advantages of using React Native?

Answer»

There are multiple ADVANTAGE of using React Native like,

  • Large Community
    React Native is an Open Source Framework, it is completely community driven so any challenges can be resolved by getting online help from other developers.
     
  • Reusability
    Code can be written once and can be used for both IOS and ANDROID, which helps in maintaining and as well debugging large complex applications as no separate teams are needed for supporting both the platforms, this also reduces the cost to a major extent.
     
  • Live and Hot Reloading
    Live reloading reloads or refreshes the ENTIRE app when a file changes. For EXAMPLE, if you were four links deep into your navigation and saved a change, live reloading would restart the app and load the app back to the initial route.
    Hot reloading only refreshes the files that were changed without losing the state of the app. For example, if you were four links deep into your navigation and saved a change to some styling, the state would not change, but the new styles would APPEAR on the page without having to navigate back to the page you are on because you would still be on the same page.
     
  • Additional Third-Party Plugins
    If the existing modules do not meet the BUSINESS requirement in React Native we can also use Third Party plugins which may help to speed up the development process.
12.

What is Flexbox and describe any elaborate on its most used properties?

Answer»

It is a layout MODEL that ALLOWS elements to align and distribute space within a container. With Flexbox when Using flexible widths and heights, all the inside the main container can be aligned to fill a space or distribute space between elements, which makes it a great tool to USE for responsive design systems.

Property ValuesDescription
flexDirection‘column’,'row'Used to specify if elements will be aligned vertically or HORIZONTALLY 
justifyContentCENTER’,'flex-start','flex-end','space-around','space-between'Used to determine how should elements be distributed inside the container 
alignItems‘center’,'flex-start','flex-end','stretched'Used to determine how should elements be distributed inside the container along the secondary axis (opposite of flexDirection)
13.

How Different is React-native from ReactJS ?

Answer»
  • Usage Scope
    ReactJs - React is a  JavaScript library for building Responsive User INTERFACES for Building Web Application.
    React Native - It is a framework for creating mobile applications with a native feel.
  • Syntax
    Both React and React Native uses JSX (JavaScript XML)  syntax but React uses html tags like <div> <h1> <p> ETC while React Native uses <view> <text> etc.
  •  Animation And Gestures
    React uses CSS animations on a major scale to achieve animations for a web page while  The recommended WAY to animate a component is to use the Animated API provided by React-Native.
  • Routing Mechanism
    React uses a react-router for routing and does not have any inbuilt routing CAPABILITIES but React Native has a built-in Navigator library for navigating mobile applications.
REACT JSREACT NATIVE
It is used for developing web applications.It is used for developing mobile applications.
It uses React-router for navigating web pages.It has a built-in navigator library for navigating mobile applications.
It uses HTML tags.It does not use HTML tags.
It provides high security.It provides low security in comparison to ReactJS.
In this, the virtual DOM renders the browser code.In this, Native uses its API to render code for mobile applications.