React Interview Q's Flashcards

1
Q

What is React?

A

It is an open-source front-end JavaScript library most popular for single-page web applications. It is helpful when interactive and complex UIs are built for websites or mobile apps. React.js was released for use in 2015 and since then it has become one of the most trusted and used technologies of recent time. It has built one of the largest developer communities around itself.

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

List some of React js’s features.

A

Important features of React.js include:

Instead of a real DOM, there is Virtual DOM
It completely renders the HTML files on the server into client HTML pages, in other words, server-side rendering
In React.js, the data can be passed to the other parts of an application only in one direction. In other words, there is a unidirectional flow of data.

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

What are the main advantages of React.js?

A

The main advantages of React.js are:

It enhances the performance of the application
It can be used from the client-side as well as the server-side
The readability of code is higher in React.js because of JSX
It offers easy integration with frameworks such as Angular, Meteor, etc.
It is easy to write UI test cases with React.js

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

What is JSX?

A

JSX is the syntax extension for Javascript in React.js. With the help of JSX, it is easy to define how the user interface should look. Additionally, with JSX, the file containing the Javascript code can be used to write the HTML structures as well.

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

Describe an event in React.js? How does this differ from an event in JS?

A

When a user presses a key, clicks the mouse, or performs any action on the machine or when the machine itself triggers an action, these actions are registered as events in React.js.

In React.js, we use camelCase to name events, instead of the lowercase in HTML
In React.js, because of JSX, a function is passed as an event handler, instead of the string in HTML.

In HTML, we specify event in html tags like onclick, onsubmit etc. and pass the string that contain the parenthesis at the end.
In html, we can also add them afterword using external javascript using addEventListener.
In React, we specify event at the time of creating our component.
we use camel case convention in React i. e. onClick, onSubmit.
In React, we bind them using method name only like onClick={greet}.
addEventListener cannot be used in React component

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

How do lists work in React.js?

A

Lists in React.js are created similar to how they are created in regular Javascript. With lists, data can be displayed in an orderly manner and is useful in displaying menus on websites. For traversing lists, the map() function is used. For example,

An array of numbers is taken by the map() function and their value is multiplied by 5
var numbers = [2,4,6,8,10]
const multiplyNums = numbers.map((number => {
return (number*5);
});
console.log (multiplyNums);
Output: The output in Javascript will be logged in the console. The output in the above case is [10, 20, 30, 40, 50]

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

What are keys used in React.js lists?

A

Keys are used in React.js Lists because:

Key helps in identifying what objects have been altered, moved, or deleted from lists
With the help of keys, it is easier to determine which objects must be re-rendered instead of all components being re-rendered all the time.
React.js interview questions that ask about the use of a certain function or component in React.js programming are common.

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

Is HTML used in React?

A

No, it uses an HTML-in JavaScript syntax called JSX (JavaScript and XML) that converts HTML tags to React elements.

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

Can you tell two downsides of React?

A

It is difficult to integrate with an MVC framework like Rails. Also, users need to have the knowledge about integrating user interface into MVC framework.

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

Can you explain the differences between real DOM and virtual DOM?

A

Real DOM and Virtual DOM differ in following ways:

Real Dom:
-updates slowly
-HTML can directly update
-Memory waste

Virtual Dom:
-Updates faster
-Can’t be updated directly
-Less memory consumption

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

Explain flux concept in React.

A

It is a new kind of architecture used for client-side web applications. Supports the concept of Unidirectional Data Flow.

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

What is Redux in React?

A

An open-source JavaScript library for front-end development and acts as a container for JavaScript applications that is used for the applications state management.

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

Explain the ‘Store’ feature.

A

It is a feature of Redux that allows the application to save the entire State at one place. This allows you to get regular updates from the store directly.

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

What is a high order component in React?

A

It is an advanced-level technique in React for reusing component logic.

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

What is the presentational segment?

A

It is a component in React that just renders HTML and its only function is presentation markup.

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

Explain props in reactjs?

A

Props in React mean properties. They act as a communication channel from parent to child.

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

What does super keyword mean in React?

A

It is used to call super or parent class.

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

What is yield catch phrase in JS?

A

It is used to delay and resume a generator work.

19
Q

List the two types of React component.

A

Two types of React component are as follows:

Function component
Class component

20
Q

What is a synthetic event in react js?

A

It is an object that serves as a cross browser wrapper of the browser’s native event.

21
Q

In Redux, what is an action?

A

In Redux, an action is an object that contains information about an event that has occurred in an application.

22
Q

What are stateless components?

A

They are pure functions with no render method.

23
Q

What is react router and why would you use it?

A

It is a library for routing in React. With React router, you can persist certain elements on the page while changing or re-rendering others that you include as sub routes. For example, the navbar can remain while the main content of the page changes. The navbar wouldn’t need to re-render which improves performance.

24
Q

Explain Jest.

A

Jest is a JavaScript framework created by Facebook and is based on Jasmine. Its feature-rich API helps to get results quickly.

25
Q

What exactly is the dispatcher?

A

It is the central hub of data flow in a Flux application that acts as a directory of callbacks.

26
Q

Explain the callback function.

A

It is called when setState () has finished. A state can be updated in response to prop changes or server response using setState() method The main purpose is to prevent a component from re-rendering.

27
Q

Explain react state.

A

It is an object which stores the component’s property values. Also, it decides how the component renders and behaves.

28
Q

Can state be updated in React.js?

A

Yes, it can be updated directly or indirectly. To implement this one can use either this. setState function or the updater function.

29
Q

What is the use of the arrow function?

A

Arrow function helps to create a compact function expression. Also they help predict bugs when passed as a callback.

30
Q

List the lifecycle steps of React.

A

The steps are as follows:

Initialization
State/Property updates
Destruction

31
Q

What are react portals?

A

They are used to render an element outside its hierarchy using CreatePortalmethod. Hence they allow developers to render outside the hierarchy tree.

32
Q

Explain Context.

A

React Context is a way to share data globally between React components. It achieved this by passing props from parent to child and storing them in a store. Thus child component(s) can use these props through the store.

33
Q

What is the use of Webpack?

A

Webpack is a command line tool used to bundle different code files and assets into single large file.. It has been built over Node.js and helps minimize Javascript, CSS files, images, etc.

34
Q

What is Babel?

A

It is an open-source JavaScript compiler that converts the latest JavaScript versions to old ones.

35
Q

How are React.js and React Native different?

A

Where ReactJS is a front end open-source JavaScript library for UIs, React Native is an open-source mobile framework for platforms such as Android and iOS.

36
Q

How do browsers read JSX files?

A

As JSX is a combination of HTML and JavaScript, browsers are unable to read it. And hence a transpiler is needed to convert JSX to Javascript so that browsers can understand.

37
Q

What is most advised way for naming components?

A

By using reference rather than using displayName because it provides a clear and concise name for the component.

38
Q

Mention one difference between props and state?

A

State is mutable while Props are immutable. This means that the state is internal and managed by the component while props are external and managed by anything that renders the component.

39
Q

What is ‘create-react-app’?

A

It provides a development environment for creating React applications using the JavaScript features as it creats a basic setup for the application without requiring to configure everything. It is very helpful in building a single-page application in React.

40
Q

What are error boundaries?

A

They help catch errors in child components, log the error and show fallback UI.

41
Q

Why will you use <></> empty tag?

A

To declare fragments

42
Q

What are mixins?

A

Mixins are a way of defining code that can be reused in multiple class hierarchies. They are intended to provide member implementations en masse. To define a mixin, use the mixin declaration. In the rare case where you need to define both a mixin and a class, you can use the mixin class declaration.

The advantage of mixins is that they can be used to simplify the design of APIs in which multiple interfaces need to include the same methods and properties.

43
Q

What is React Query?

A

React Query is a popular library for managing server state and caching in React applications. It provides hooks and utilities to fetch, cache, and update data from your server in a declarative and efficient way.

Some key features of React Query include:

  1. Data Fetching: React Query provides hooks like useQuery and useMutation to fetch and mutate data from your server. These hooks handle caching, stale-while-revalidate, and other optimizations out of the box.
  2. Automatic Caching: It automatically caches query results in memory and supports various cache configurations to control caching behavior, including time-based invalidation and manual invalidation.
  3. Query Invalidation and Refetching: React Query handles automatic invalidation and refetching of queries when data changes, ensuring that your UI stays up to date with the latest data from the server.
  4. Optimistic Updates: It supports optimistic updates for mutations, allowing you to update the UI optimistically before receiving a response from the server, providing a smoother user experience.
  5. Pagination and Infinite Loading: React Query includes built-in support for pagination and infinite loading, making it easy to implement efficient data fetching patterns in your application.
  6. Server-Side Rendering (SSR) Support: It provides built-in support for server-side rendering (SSR) and seamless integration with popular SSR frameworks like Next.js.

Overall, React Query simplifies the management of server state in React applications, reducing boilerplate code and improving performance by handling caching and data fetching optimizations for you.

44
Q

What is the context API?

A

The Context API in React is a mechanism for passing data through the component tree without having to pass props down manually at every level. It allows you to share values like themes, locale preferences, or authentication status across the entire React component tree.

The Context API consists of two main parts:

  1. Context Provider: The Context Provider component is used to wrap a part of the component tree where you want to make certain data available to all descendant components. It accepts a value prop which can be accessed by any child component that subscribes to the context.
  2. Context Consumer: The Context Consumer component is used to consume the context value within a functional component. It allows components to access the context value without having to explicitly pass it down through props.

Here’s a basic example of how the Context API works:

```javascript
// Create a new context
const MyContext = React.createContext();

// Define a Context Provider
function MyProvider({ children }) {
const [value, setValue] = React.useState(‘defaultValue’);

return (
<MyContext.Provider value={{ value, setValue }}>
{children}
</MyContext.Provider>
);
}

// Define a component that consumes the context
function MyComponent() {
return (
<MyContext.Consumer>
{({ value, setValue }) => (
<div>
<p>Value from context: {value}</p>
<button onClick={() => setValue('newValue')}>
Change Value
</button>
</div>
)}
</MyContext.Consumer>
);
}

// Usage
function App() {
return (
<MyProvider>
<MyComponent></MyComponent>
</MyProvider>
);
}
~~~

In this example, MyProvider is the Context Provider, which wraps the MyComponent. MyComponent consumes the context value using the Context Consumer. When the button inside MyComponent is clicked, it updates the context value through the setter function provided by the context. All components within the provider will re-render with the updated value.