Docsity

Front-End Web Development / JavaScript Frameworks, Exercises of Web Programming and Technologies

Toggle sidebar
bg1
Top 26+ React Interview Questions (2026 Edition)
What is React? - ✔✔React is an open-source JavaScript library created by Facebook for building complex,
interactive UIs in web and mobile applications. React's core purpose is to build UI components; it is often
referred to as just the "V" (View) in an "MVC" architecture.
What are the advantages of ReactJS? - ✔✔Below are the advantages of ReactJS:
Increases the application's performance with Virtual DOM
JSX makes code is easy to read and write
It renders both on client and server side
Easy to integrate with other frameworks (Angular, BackboneJS) since it is only a view library
Easy to write UI Test cases and integration with tools such as JEST.
What are the major features of ReactJS? - ✔✔The major features of ReactJS are as follows,
It uses VirtualDOM instead RealDOM considering that RealDOM manipulations are expensive.
Supports server-side rendering
Follows Unidirectional data flow or data binding
Uses reusable/composable UI components to develop the view
What is virtual DOM? - ✔✔The virtual DOM (VDOM) is an in-memory representation of Real DOM. The
representation of a UI is kept in memory and synced with the "real" DOM. It's a step that happens
between the render function being called and the displaying of elements on the screen. This entire
process is called reconciliation.
What is Redux? - ✔✔Redux is a predictable state container for JavaScript apps based on the Flux design
pattern. Redux can be used together with ReactJS, or with any other view library. It is tiny (about 2kB)
and has no dependencies.
Academia Hall
Academia Hall
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Front-End Web Development / JavaScript Frameworks and more Exercises Web Programming and Technologies in PDF only on Docsity!

Top 26+ React Interview Questions (20 26 Edition)

What is React? - ✔✔React is an open-source JavaScript library created by Facebook for building complex, interactive UIs in web and mobile applications. React's core purpose is to build UI components; it is often referred to as just the "V" (View) in an "MVC" architecture. What are the advantages of ReactJS? - ✔✔Below are the advantages of ReactJS: Increases the application's performance with Virtual DOM JSX makes code is easy to read and write It renders both on client and server side Easy to integrate with other frameworks (Angular, BackboneJS) since it is only a view library Easy to write UI Test cases and integration with tools such as JEST. What are the major features of ReactJS? - ✔✔The major features of ReactJS are as follows, It uses VirtualDOM instead RealDOM considering that RealDOM manipulations are expensive. Supports server-side rendering Follows Unidirectional data flow or data binding Uses reusable/composable UI components to develop the view What is virtual DOM? - ✔✔The virtual DOM (VDOM) is an in-memory representation of Real DOM. The representation of a UI is kept in memory and synced with the "real" DOM. It's a step that happens between the render function being called and the displaying of elements on the screen. This entire process is called reconciliation. What is Redux? - ✔✔Redux is a predictable state container for JavaScript apps based on the Flux design pattern. Redux can be used together with ReactJS, or with any other view library. It is tiny (about 2kB) and has no dependencies.

What is Flux? - ✔✔Flux is an application design paradigm used as a replacement for the more traditional mvc pattern. It is not a framework or a library but a new kind of architecture that complements React and the concept of Unidirectional Data Flow. Facebook used this pattern internally when working with React The workflow between dispatcher, stores and views components with distinct inputs and outputs as follows: https://github.com/sudheerj/reactjs-interview-questions/raw/master/images/flux.png What's the difference between an "Element" and a "Component" in React? - ✔✔Simply put, a React element describes what you want to see on the screen. Not so simply put, a React element is an object representation of some UI. A React component is a function or a class which optionally accepts input and returns a React element (typically via JSX which gets transpiled to a createElement invocation). What are the limitations of ReactJS? - ✔✔Below are the list of limitations: React is just a view library, not a full-blown framework There is a learning curve for beginners who are new to web development. Integrating React.js into a traditional MVC framework requires some additional configuration The code complexity increases with inline templating and JSX. Too many smaller components leading to over-engineering or boilerplate What is the difference between a Presentational component and a Container component? - ✔✔Presentational components are concerned with how things look. They generally receive data and callbacks exclusively via props. These components rarely have their own state, but when they do it generally concerns UI state, as opposed to data state. Container components are more concerned with how things work. These components provide the data and behavior to presentational or other container components. They call Flux actions and provide these as callbacks to the presentational components. They are also often stateful as they serve as data sources. How is React different from AngularJS (1.x)? - ✔✔For example, AngularJS (1.x) approaches building an application by extending HTML markup and injecting various constructs (e.g. Directives, Controllers,

render() { return (

{this.state.message}

); } } What is the difference between state and props? - ✔✔Both props and state are plain JavaScript objects. While both of them hold information that influences the output of render, they are different in their functionality with respect to component. i.e, Props get passed to the component similar to function parameters state is managed within the component similar to variables declared within a function. What can you tell me about JSX? - ✔✔When Facebook first released React to the world, they also introduced a new dialect of JavaScript called JSX that embeds raw HTML templates inside JavaScript code. JSX code by itself cannot be read by the browser; it must be transpiled into traditional JavaScript using tools like Babel and webpack. While many developers understandably have initial knee-jerk reactions against it, JSX (in tandem with ES2015) has become the defacto method of defining React components. class MyComponent extends React.Component { render() { let props = this.props; return (

{props.name}

);

Why should not we update the state directly? - ✔✔If you try to update state directly then it won't re- render the component. //Wrong This.state.message ="Hello world"; Instead use setState() method. It schedules an update to a component's state object. When state changes, the component responds by re-rendering //Correct This.setState({message: 'Hello World'}); Note: The only place you can assign the state is constructor. What are the different phases of ReactJS component lifecycle? - ✔✔There are four different phases of React component's lifecycle: Initialization: In this phase react component prepares setting up the initial state and default props. Mounting: The react component is ready to mount in the browser DOM. This phase covers componentWillMount and componentDidMount lifecycle methods. Updating: In this phase, the component get updated in two ways, sending the new props and updating the state. This phase covers shouldComponentUpdate, componentWillUpdate and componentDidUpdate lifecycle methods. Unmounting: In this last phase, the component is not needed and get unmounted from the browser DOM. This phase include componentWillUnmount lifecycle method. https://raw.githubusercontent.com/sudheerj/reactjs-interview-questions/master/images/phases.png

Why ReactJS uses className over class attribute? - ✔✔class is a keyword in javascript and JSX is an extension of javascript. That's the principal reason why React uses className instead of class. render() { return Menu } How to access redux store outside a react component? - ✔✔Yes.You just need to export the store from the module where it created with createStore. Also, it shouldn't pollute the global window object What are the downsides of Redux over Flux? - ✔✔Instead of saying downsides we can say that there are few compromises of using Redux over Flux. Those are as follows: You will need to learn avoiding mutations: Flux is un-opinionated about mutating data, but Redux doesn't like mutations and many packages complementary to Redux assume you never mutate the state. You can enforce this with dev-only packages like redux-immutable-state-invariant, Immutable.js, or your team to write non-mutative code. You're going to have to carefully pick your packages: While Flux explicitly doesn't try to solve problems such as undo/redo, persistence, or forms, Redux has extension points such as middleware and store enhancers, and it has spawned a young but rich ecosystem. This means most packages are new ideas and haven't received the critical mass of usage yet There is no nice Flow integration yet: Flux currently lets you do very impressive static type checks which Redux doesn't support yet. What is the difference between a controlled component and an uncontrolled component? - ✔✔A controlled component is a component where React is in control and is the single source of truth for the form data.

An uncontrolled component is where your form data is handled by the DOM, instead of inside your React component. Though uncontrolled components are typically easier to implement since you just grab the value from the DOM using refs, it's typically recommended that you favor controlled components over uncontrolled components. The main reasons for this are that controlled components support instant field validation, allow you to conditionally disable/enable buttons, enforce input formats, and are more "the React way". What is wrong with this code? - ✔✔Questions: What is wrong with this code? this.setState((prevState, props) => { return { streak: prevState.streak + props.count } }) Answer: Nothing is wrong with it. It's rarely used and not well known, but you can also pass a function to setState that receives the previous state and props and returns a new state, just as we're doing above. And not only is nothing wrong with it, but it's also actively recommended if you're setting state based on previous state. Why would you use forceUpdate in a React component? - ✔✔In order to force a re-render if there is some condition React is not detecting that requires an update to the UI. Typically this should not be necessary to call. Describe Flux vs MVC? - ✔✔Traditional MVC patterns have worked well for separating the concerns of data (Model), UI (View) and logic (Controller) — but MVC architectures frequently encounter two main problems: