Questions React Flashcards

Questions about react and js focused on interviews

1
Q

What is React js?

A

React.js is a JavaScript library used for building user interfaces, particularly for single-page applications. It allows developers to create reusable UI components that efficiently update and render based on data changes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the difference between virtual DOM and the real DOM in React js?

A

The virtual DOM is a lightweight copy of the real DOM kept in memory. React uses it to compute the most efficient way to update the browser’s displayed DOM. This process minimizes actual DOM updates, which can be resource-intensive and slow.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a controlled and uncontrolled component in React js?

A

Controlled components are React components whose form elements (like input, textarea, select) are controlled by React via state. Uncontrolled components allow the form elements to manage their own state.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are hooks in React js?

A

Hooks are functions that let you use React state and lifecycle features in functional components. Examples include useState for managing state and useEffect for handling side effects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is JSX, Babel, and Webpack?

A

JSX (JavaScript XML) is a syntax extension for JavaScript used with React to describe what the UI should look like. Babel is a tool that converts JSX and newer JavaScript features into widely supported ES5 code. Webpack is a module bundler that processes these files for web deployment.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is Redux?

A

Redux is a predictable state container for JavaScript applications, commonly used with React for managing application state in a predictable and centralized manner.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a reducer, action, and store in Redux?

A

In Redux, a reducer is a pure function that takes the previous state and an action, and returns the next state. Actions are payloads of information that send data from your application to your Redux store. The store holds the complete state tree of the application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is middleware in Redux?

A

Middleware in Redux provides a third-party extension point between dispatching an action and the moment it reaches the reducer. It is commonly used for logging, crash reporting, or asynchronous API calls.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Explain the data flow in Redux

A

The data flow in Redux is unidirectional. Actions are dispatched to the store, which calls the reducer to update the state. The updated state then re-renders any connected React components.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is Redux-Thunk?

A

Redux-Thunk is a middleware for Redux that allows you to write action creators that return a function instead of an action. This enables handling of asynchronous operations like API calls within Redux.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is Redux-Saga, and what’s the difference between Redux-Thunk and Redux-Saga?

A

Redux-Saga is another Redux middleware used to handle side effects in a more structured way using ES6 Generators. Redux-Thunk uses functions, while Redux-Saga uses Generator functions, offering more complex control flow and capabilities.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Difference between class component and function component.

A

Class components are ES6 classes that extend from React.Component and have a state, lifecycle methods, and can hold local state. Function components are stateless and are simply JavaScript functions that take props as arguments and return JSX.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How can we implement componentWillUnmount in a function component?

A

You can use the useEffect hook in combination with a cleanup function to replicate componentWillUnmount behavior in function components. By returning a cleanup function from useEffect, you can perform cleanup tasks when the component is unmounted.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Explain useEffect, useState, useMemo, useCallback hooks in detail.

A

useEffect: Executes side effects in function components (e.g., data fetching, subscriptions) and replaces lifecycle methods like componentDidMount, componentDidUpdate, and componentWillUnmount.
useState: Allows function components to have local state.
useMemo: Memoizes the result of a function, avoiding unnecessary recalculations.
useCallback: Memoizes a callback function, preventing unnecessary re-renders of child components.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Explain lifecycle methods in React js.

A

Lifecycle methods are methods that are automatically invoked at different phases of a component’s lifecycle (e.g., mounting, updating, unmounting). Examples include componentDidMount, componentDidUpdate, and componentWillUnmount.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the difference between export default and export in React js?

A

export default is used to export a single class, function, or primitive as the default export of a module. export is used to export one or more functions, objects, or primitives from a module.

17
Q

What is a portal in React js?

A

Portals in React provide a way to render children into a DOM node that exists outside the DOM hierarchy of the parent component. This is useful for scenarios like modals or tooltips that need to break out of their parent’s styles and z-index constraints.

18
Q

What is reconciliation in React js?

A

Reconciliation is the process through which React updates the DOM to match the React components’ desired state efficiently. It involves comparing the new element tree with the previous one and making necessary updates to minimize DOM manipulations.

19
Q

What is useRef in React js?

A

useRef is a hook that returns a mutable ref object whose .current property is initialized to the passed argument (initialValue). It allows you to access DOM nodes or React elements directly within functional components.

20
Q

What is server-side rendering in React js?

A

Server-side rendering (SSR) is the process of rendering React components on the server instead of the client browser. This enables faster initial page loads and better SEO, as the server sends fully rendered HTML to the client.

21
Q

What is “useStrict” in React js?

A

It seems there might be a confusion here; “useStrict” is not a specific concept in React. However, JavaScript’s “use strict”; directive enables strict mode, which helps catch common coding mistakes and makes code more secure.

22
Q

What is a fragment in React js?

A

A fragment is a way to group multiple children elements in React without adding extra nodes to the DOM. It allows you to return multiple elements from a component’s render method.

23
Q

What is React Router in React js?

A

React Router is a library that provides routing capabilities for single-page applications in React. It enables navigation among views/components and ensures the UI synchronizes with the URL.

24
Q

What is a Node module in React js?

A

Node modules are reusable JavaScript packages or libraries that can be imported and used in Node.js applications, including React projects. They are managed by npm (Node Package Manager).

25
Q

What is the default localhost server port in React js, and how can we change it?

A

The default localhost server port for React development is usually 3000. You can change the port by specifying a different port number in the package.json scripts section (e.g., “start”: “react-scripts start –port 4000”).

26
Q

What is a higher-order component (HOC) in React js?

A

A higher-order component is a pattern in React where a function takes a component and returns a new component with enhanced functionality. It allows code reuse, logic abstraction, and composition of multiple behaviors.

27
Q

What is a pure component in React js?

A

A pure component is a class component in React that extends React.PureComponent instead of React.Component. It performs a shallow comparison of props and state to determine whether to re-render, optimizing performance.

28
Q

What is the difference between state and props in React js?

A

State is internal data managed within a component, while props (short for properties) are data passed to a component from its parent. State can be changed by the component itself, whereas props are immutable.

29
Q

How to optimize a React js app?

A

React app optimization involves techniques like code splitting, lazy loading, minimizing render cycles using shouldComponentUpdate or React.memo, optimizing images, using production builds, and reducing unnecessary re-renders.

30
Q

What is the difference between React js and Angular js?

A

React is a JavaScript library primarily for building UI components, while Angular is a complete framework for building large-scale, single-page applications (SPAs). React uses a virtual DOM, whereas Angular uses two-way data binding.

31
Q

What is prop drilling in React js, and how to overcome it?

A

Prop drilling is the process where props are passed through multiple layers of components, even if some intermediate components do not directly use those props. To overcome prop drilling, you can use Context API or implement state management libraries like Redux.

32
Q

What is the Context API in React js?

A

The Context API in React provides a way to pass data through the component tree without having to pass props manually at every level. It’s useful for sharing state between components that are not directly connected in the component tree.

33
Q

What are super, constructor, and render function in React js?

A

super: Calls the constructor of the parent class within a child class constructor.
constructor: A special method for initializing state and binding methods in React class components.
render: A required method that returns React elements describing the UI to be rendered. It’s responsible for rendering the component structure.