Category: React Native Interview Question

https://cdn3d.iconscout.com/3d/premium/thumb/interview-question-3d-icon-download-in-png-blend-fbx-gltf-file-formats–interviewer-hr-manager-pack-business-icons-9684875.png?f=webp

  • What is state in the React component?

    State is another way apart from props by which we can modify a React component. React component’s state value changes in the life cycle of component, unlike props. We should not directly change state value of react component. React framework gives the setState method by which state of a component should be changed.

    React framework
    import React from 'react';
    import { View, Text, StyleSheet, TouchableOpacity } from 'react-native';
    
    class Counter extends React.Component {
        state = { count: 0 };
        increment = () => this.setState({count: this.state.count + 1});
        decrement = () => this.setState({count: this.state.count - 1});
        render() {
            return (
                <View style={styles.container}>
                    <TouchableOpacity onPress={this.decrement}>
                        <Text style={styles.text}>-</Text>
                    </TouchableOpacity>
                    <Text style={styles.text}>{this.state.count}</Text>
                    <TouchableOpacity onPress={this.increment}>
                        <Text style={styles.text}>+</Text>
                    </TouchableOpacity>
                </View>
            );
        }
    };
    const styles = StyleSheet.create({
        container: {
            flexDirection: 'row',
            borderRadius: 5,
            borderWidth: 1,
            borderColor: '#1a91b8',
            padding: 5,
            backgroundColor: '#eaf7fd'
        },
        text: {
            color: '#015169',
            fontWeight: 'bold',
            fontSize: 20,
            padding: 15
        }
    });
    export default Counter;

    Above code is an implementation of a counter component. This component has a state count whose value is changed by clicking on the plus (+) and minus (-) button. As the state count of this component is changing the number displayed on UI is also changing. Whenever we create any component in React, first we divide the screen in the component then decide what state a component should have. The beauty of this component is that it is an independent component and can be used anywhere in the application. That is how we make several fully functional component in React to build the complete application.

  • What are props in React Component?

    Props are parameters which are used to customise a component at the time of creation and on re-render. Props are like arguments passed to a React component. For example, Image is a very basic component provided by React Native library to display an image. It accepts a prop called source which is used to control what image it shows. By passing different values of props, one component can show different UI and different functionality. So we can say that props help use and reuse the same component at different places. Props are set by the parent component and remain fixed for an entire lifecycle of a component.

    React Component
    import React from 'react';
    import { StyleSheet, Text, View, Image } from 'react-native';
    import Counter from './components/Counter';
    import Greeting from "./components/Greeting2";
    import SimpleTextInput from './components/SimpleTextInput';
    import SimpleButton from './components/SimpleButton';
    import LoginForm from './components/LoginForm';
    import PictureList from './components/PictureList';
    
    export default class App extends React.Component {
      render() {
        const pictureData = {
          uri: 'https://picsum.photos/300/300'
        };
        return (
          <View style={styles.container}>
            <PictureList />
          </View>
        );
      }
    }
    
    const styles = StyleSheet.create({
      container: {
        flex: 1,
        backgroundColor: '#f5fcff',
        alignItems: 'center',
        justifyContent: 'center',
      },
      image: {
        margin: 5,
        borderRadius: 5,
        width: 300,
        height: 300
      }
    });
  • What is component driven development and what are the benefits of using component driven development?

    Long time back, web developer realises that there are few elements which are frequently used in web development like drop down and different type of button. The developer started making CSS frameworks which provide already developed components. Bootstrap was first very popular CSS framework which helped web developer to build user experience very quickly. React also follows the same approach in web development. 

    Component driven development is a methodology where we break the complete UI design into several small reusable components and develop them independently. Then the complete UI is built by composing these small components. This methodology helps us write UI code in a modular way. UI development will be faster as we will be reusing components at multiple places. Less code also results in less effort in maintaining the code and also less number of bugs. So we can say that component driven development was already there in web development but React JS made it very popular in the developer community. New frameworks like Angular4+ are also following the same methodology to develop the web application.

  • What is JSX?

    JSX is a system used for embedding XML in Javascript. You can say that JSX is a templating language for writing HTML/XML tags with Javascript. With the help of JSX, HTML/XML can be written inside Javascript file. JSX enables conditional rendering of React components. React includes building step which converts JSX into Javascript code which is ultimately executed by browser in case of a web app or react Native in case of React Native. JSX is added to improve the developer experience. ReactJS provides few APIs which make the HTML structure in a browser. Those APIs were a little cumbersome to frequently used. That is why React JS introduced JSX and added a tooling step to convert JSX into platform understandable code. With the help of JSX, we can execute javascript to build HTML tags very easily.  Here is an example of a JSX code:

    <View style={styles.container}>
    <TouchableOpacity onPress={this.decrement}>
    <Text style={styles.text}>-</Text>
    </TouchableOpacity>
    <Text style={styles.text}>{this.state.count}</Text>
    <TouchableOpacity onPress={this.increment}>
    <Text style={styles.text}>+</Text>
    </TouchableOpacity>
    </View>

    Above JSX code is creating one View component which contains two TouchableOpacity component as its child element. We are accessing Javascript variable in Text component with curly brace.

  • How mobile app development with React Native is different than web app development with ReactJS

    I’m listing down set of categories that shows how mobile app development is different than web app development using react —  

    Origin and Architecture: Both developed and open-sourced by Facebook Inc., React Native follows ReactJS’s basic architecture and promotes a component-based approach to building mobile screens. They share similar lifecycle methods.

    UI Components: 

    • ReactJS: Uses HTML tags like div, span, etc. 
    • React Native: Uses components like View and Text from the React Native library. 

    Platform and Browser Features: 

    • ReactJS: Built for web applications, allowing access to browser features like the window object and local storage. 
    • React Native: Built for native platforms, lacking access to browser-specific features. 

    GitHub Projects: ReactJS and React Native are separate open-source projects on GitHub. 

    Feature ImplementationNew component architecture features are first implemented in ReactJS and later added to React Native. 

    Development ToolsBoth frameworks have different tools for getting started with development. 

    Static Type Checking: 

    • React NativeComes with static type checking enabled by default. 
    • ReactJS: Requires additional steps to enable flow static type checking. 

    The above list of differentiation make clear how react and react native are works and different. 

  • What tool and skill set do you need to develop a mobile app in React Native?

    Developer experience is one of the most important attributes of a framework. If getting started step with any framework is very difficult and very complex then the community will take lots of time to accept that framework. That is why React native has tried their best to simplify the getting started step for app development. To build a mobile app with React Native, one should have a good understanding of Javascript concepts and understanding of CSS helps in styling React Native app. React Native provide CLI (command line interface) which is used to bootstrap the mobile application. 

    For IOS development Xcode and for Android app development, Android studio is required. Understanding of component driven development with ReactJs is also very beneficial in React Native app development. There is one more open source project named Expo CLI which provides a command line utility to easily start development of React native. It also provides barcode based approach to share the app within the team. Developer experience is pretty good for React native that is also one of the reasons for its huge popularity in the developer community.

  • Name a few companies or applications that are built using React Native?

    Many renowned companies are developing their mobile apps with React Native. Big names like Facebook, Airbnb, Instagram, Pinterest, Uber, and Tesla have their main consumer-facing mobile apps built using this framework. This widespread adoption demonstrates their trust in React Native. 

    Airbnb was an early adopter of React Native and actively shared their experiences with the framework. They also open-sourced many React Native libraries they built, one of the most famous being Lottie, which enables complex animations in React Native. 

    Many startups are also using React Native to build their mobile apps, allowing them to quickly launch their ideas on both Android and iOS platforms simultaneously. Instagram, another example, uses React Native and handles large user interactions effectively. 

    This clearly shows that React Native is a mature and robust mobile app development framework available today.

  • How is React Native different from other frameworks for developing a mobile application?

    Javascript developer always tried to explore platforms where Javascript can be used to build better user experiences. React native is not the first framework which enables web developers to build applications for the mobile platform. Ionic, Cordova were few very popular application framework which was used to develop a mobile application using web technologies. One major motivation towards this effort was having a seamless experience on all the platforms. Mobile application developed with React Native is different than alternate frameworks in the following ways:

    1. React Native app is a real mobile app, not a web app running inside a mobile app shell. Other alternative like Cordova, ionic run a web app in a web view.
    2. React Native app is converted into machine code which runs on mobile that is why it gives better performance than other alternatives.
    3. React Native mobile apps are more close to Native app development in comparison to other Javascript frameworks
    4. Mobile application built with React native has small bundle size in comparison to older hybrid application development framework.
  • What are the benefits of using React Native for building mobile applications?

    There are following benefits of using React Native in mobile application development

    1. React Native enables a web developer to build mobile apps with Javascript.
    2. The developer doesn’t need to learn complete new programming language java/ Kotlin to develop Android App. Similarly, the developer doesn’t need to be an expert in objective C or swift to develop IOS app anymore. Javascript is more than sufficient to build a mobile app for both Android and IOS. However, knowing java or swift helps the developer to write performance robust mobile app.
    3. With React Native, most of the code base can be shared between the Android app and the IOS app.
    4. With a single code base, effort in maintenance is reduced by many folds.
    5. With a single code base, features can be shipped much faster on both major mobile platform
    6. Developer having experience with ReactJs can quickly learn React Native. The learning curve for a developer is very low.
    7. App developed with React Native is not a web app running inside a mobile app. It is a real mobile app because it uses the same fundamental building blocks as regular IOS native app and Android app uses.
    8. React Native lets you build an app faster as it’s tool gives hot reloading functionality out of the box which means we don’t need to recompile app again and again on making changes.
    9. React Native gives the flexibility to use Native swift or java module with React Native application. So your app can get the best from both worlds.
  • What is React Native?

    React Native Overview: 

    • Developed by Facebook. 
    • Enables cross-platform mobile app development using JavaScript. 
    • Uses design principles from ReactJS. 

    UI Development: 

    • Compose mobile application UI using multiple components declaratively. 

    Comparison with Previous Options: 

    • Previous frameworks: Cordova, Ionic. 
    • Hybrid apps using these frameworks lacked native performance. 

    Performance: 

    • React Native bridge invokes native rendering APIs (Objective-C for iOS, Java for Android). 
    • Provides better performance than hybrid frameworks. 

    Community and Popularity: 

    • Active developer community. 
    • Code available on GitHub with over 70k stars. 
    • Quickly gained popularity in the React community.