FrontendDeveloper.in

React Interview Questions

  • Question 136

    How to add multiple middlewares to Redux?

    You can use applyMiddleware().

    For example, you can add redux-thunk and logger passing them as arguments to applyMiddleware():

    import { createStore, applyMiddleware } from "redux";
    const createStoreWithMiddleware = applyMiddleware(
    ReduxThunk,
    logger
    )(createStore);
    
  • Question 137

    How to set initial state in Redux?

    You need to pass initial state as second argument to createStore:

    const rootReducer = combineReducers({
    todos: todos,
    visibilityFilter: visibilityFilter,
    });
    
    const initialState = {
    todos: [{ id: 123, name: "example", completed: false }],
    };
    
    const store = createStore(rootReducer, initialState);
    
  • Question 138

    How Relay is different from Redux?

    Relay is similar to Redux in that they both use a single store. The main difference is that relay only manages state originated from the server, and all access to the state is used via GraphQL queries (for reading data) and mutations (for changing data). Relay caches the data for you and optimizes data fetching for you, by fetching only changed data and nothing more.

  • Question 139

    What is an action in Redux?

    Actions are plain JavaScript objects or payloads of information that send data from your application to your store. They are the only source of information for the store. Actions must have a type property that indicates the type of action being performed.

    For example, let's take an action which represents adding a new todo item:

    {
    type: ADD_TODO,
    text: 'Add todo item'
    }
    

    React Native

  • Question 140

    What is the difference between React Native and React?

    React is a JavaScript library, supporting both front end web and being run on the server, for building user interfaces and web applications.

    React Native is a mobile framework that compiles to native app components, allowing you to build native mobile applications (iOS, Android, and Windows) in JavaScript that allows you to use React to build your components, and implements React under the hood.

  • Question 141

    How to test React Native apps?

    React Native can be tested only in mobile simulators like iOS and Android. You can run the app in your mobile using expo app (https://expo.io) Where it syncs using QR code, your mobile and computer should be in same wireless network.

  • Question 142

    How to do logging in React Native?

    You can use console.log, console.warn, etc. As of React Native v0.29 you can simply run the following to see logs in the console:

    $ react-native log-ios
    $ react-native log-android
    
  • Question 143

    How to debug your React Native?

    Follow the below steps to debug React Native app:

    1. Run your application in the iOS simulator.
    2. Press Command + D and a webpage should open up at http://localhost:8081/debugger-ui.
    3. Enable Pause On Caught Exceptions for a better debugging experience.
    4. Press Command + Option + I to open the Chrome Developer tools, or open it via View -> Developer -> Developer Tools.
    5. You should now be able to debug as you normally would.

    React supported libraries & Integration

  • Question 144

    What is reselect and how it works?

    Reselect is a selector library (for Redux) which uses memoization concept. It was originally written to compute derived data from Redux-like applications state, but it can't be tied to any architecture or library.

    Reselect keeps a copy of the last inputs/outputs of the last call, and recomputes the result only if one of the inputs changes. If the same inputs are provided twice in a row, Reselect returns the cached output. It's memoization and cache are fully customizable.

  • Question 145

    What is Flow?

    Flow is a static type checker designed to find type errors in JavaScript. Flow types can express much more fine-grained distinctions than traditional type systems. For example, Flow helps you catch errors involving null, unlike most type systems.

  • Question 146

    What is the difference between Flow and PropTypes?

    Flow is a static analysis tool (static checker) which uses a superset of the language, allowing you to add type annotations to all of your code and catch an entire class of bugs at compile time.

    PropTypes is a basic type checker (runtime checker) which has been patched onto React. It can't check anything other than the types of the props being passed to a given component. If you want more flexible typechecking for your entire project Flow/TypeScript are appropriate choices.

  • Question 147

    How to use Font Awesome icons in React?

    The below steps followed to include Font Awesome in React:

    1. Install font-awesome:
    $ npm install --save font-awesome
    
    1. Import font-awesome in your index.js file:
    import "font-awesome/css/font-awesome.min.css";
    
    1. Add Font Awesome classes in className:
    function MyComponent {
    return <div><i className={'fa fa-spinner'} /></div>
    }
    
  • Question 148

    What is React Dev Tools?

    React Developer Tools let you inspect the component hierarchy, including component props and state. It exists both as a browser extension (for Chrome and Firefox), and as a standalone app (works with other environments including Safari, IE, and React Native).

    The official extensions available for different browsers or environments.

    1. Chrome extension
    2. Firefox extension
    3. Standalone app (Safari, React Native, etc)
  • Question 150

    How to use Polymer in React?

    You need to follow below steps to use Polymer in React,

    1. Create a Polymer element:
    <link
    rel="import"
    href="../../bower_components/polymer/polymer.html"
    />;
    Polymer({
    is: "calendar-element",
    ready: function () {
    this.textContent = "I am a calendar";
    },
    });
    
    1. Create the Polymer component HTML tag by importing it in a HTML document, e.g. import it in the index.html of your React application:
    <link
    rel="import"
    href="./src/polymer-components/calendar-element.html"
    />
    
    1. Use that element in the JSX file:
    export default function MyComponent {
    return <calendar-element />;
    }
    
Get LinkedIn Premium at Rs 399