General Flashcards

1
Q

What is React.js, and what problem does it solve in web development?

A

React.js is an open-source JavaScript library for building user interfaces and single-page applications. It solves several problems in web development, including complex UIs, efficient updates, data flow management, component reusability, and a strong community and ecosystem.

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

Explain the concept of “virtual DOM” in React and how it improves performance.

A

The virtual DOM is a lightweight copy of the actual DOM in a web application. When changes occur in a React application, React first updates the virtual DOM, then compares it to the real DOM, and finally updates only the parts of the real DOM that have changed. This process reduces direct manipulation of the DOM, leading to improved performance and faster UI updates.

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

What is JSX in React, and why is it used?

A

JSX (JavaScript XML) is a syntax extension in React that allows you to write HTML-like code within JavaScript. JSX makes it easier to define and render React components, improving code readability and maintainability.

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

How do you create a functional component in React?

A

You create a functional component in React by defining a JavaScript function that returns JSX.

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

What is a class component in React, and how does it differ from a functional component?

A

Class components in React are created using JavaScript classes that extend React.Component. They can manage local state and have access to lifecycle methods. Functional components, on the other hand, are defined as JavaScript functions and traditionally didn’t manage state or have access to lifecycle methods. However, with the introduction of hooks, functional components can now manage state and handle side effects, blurring the distinction between the two.

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

How can you pass data from a parent component to a child component in React?

A

You can pass data from a parent component to a child component in React by using props. Props (short for properties) are attributes that you can attach to a component when you use it. The parent component passes data to the child component by setting props on the child component when rendering it.

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

What is the purpose of the setState method in React, and why is it important?

A

The setState method in React is used to update a component’s local state. It’s important because it triggers a re-render of the component when the state changes, ensuring that the UI reflects the updated state. It also helps maintain a predictable data flow in a React application.

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

What are props in React, and how are they used to pass data between components?

A

Props (short for properties) in React are a way to pass data from a parent component to a child component. They are read-only and help create dynamic and reusable components. Props are defined as attributes in the JSX when rendering a component and are accessed as an object within the child component.

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

Explain the lifecycle methods in React. Name a few key lifecycle methods and their purposes.

A

React lifecycle methods are special methods that automatically get called at various points in a component’s lifecycle. Some key lifecycle methods include:

componentDidMount: Called after the component is rendered to the DOM. Used for side effects like data fetching.
componentDidUpdate: Called after a component’s state or props change. Used for reacting to changes in the component.
componentWillUnmount: Called before a component is removed from the DOM. Used for cleanup operations.

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

What is Redux, and why might you use it in a React application?

A

Redux is a state management library for JavaScript applications, often used with React. It provides a centralized store to manage application state, making it easier to manage and share data between different parts of a React application, especially in larger and more complex applications.

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

How does React Router help with client-side routing in a React application?

A

React Router is a library for managing routing and navigation in a React application. It allows you to define different “routes” in your application and render specific components when the URL matches those routes. This enables client-side navigation without full page refreshes, creating a smoother user experience in single-page applications.

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

What are hooks in React, and why were they introduced?

A

Hooks are functions that allow functional components to “hook into” React state and lifecycle features. They were introduced to functional components in React 16.8 to provide a more direct API for managing state and side effects, making functional components more powerful and easier to work with.

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

What is the significance of the useEffect hook in React, and when would you use it?

A

The useEffect hook in React is used for handling side effects in functional components. It allows you to perform actions like data fetching, DOM manipulation, or subscribing to external data sources. You would use it when you need to run code in response to component updates, similar to componentDidMount, componentDidUpdate, and componentWillUnmount in class components.

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

How can you optimize performance in a React application?

A

Performance optimization in React can be achieved through various techniques such as:

Memoization and memoization libraries like React.memo.
Code splitting to load only necessary code when needed.
Using the shouldComponentUpdate method or PureComponent for class components.
Employing PureComponent or memoization for functional components.
Implementing lazy loading for components.
Properly using keys when rendering lists to aid React in identifying changes.

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

What is the purpose of the key prop when rendering lists of elements in React?

A

The key prop is used when rendering lists of elements in React to help React identify which items have changed, been added, or been removed. It should be a unique identifier for each item in the list and is crucial for efficient list rendering and updates.

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

Explain the concept of “controlled” and “uncontrolled” components in React.

A

Controlled Components: In controlled components, form elements like input fields, checkboxes, and radio buttons are bound to React state. Their values and behavior are controlled by React through state, and any changes in the UI are reflected in the state.
Uncontrolled Components: In uncontrolled components, form elements retain their own internal state, and React doesn’t manage their values directly. You can access their values via DOM references. Uncontrolled components are useful in cases where you need to integrate with non-React code or handle form elements outside of React’s state management.

17
Q

How can you handle forms in React, and what is the role of the onChange event?

A

In React, you can handle forms by using controlled components, where form elements are connected to React state, and the onChange event is used to capture user input. The onChange event handler updates the state based on user input, allowing you to control and validate form data.

18
Q

What is the role of the map function in React when rendering lists of elements?

A

The map function is used to transform and render lists of elements in React. It allows you to iterate over an array of data and return a new array of React elements. This is commonly used to generate a list of components based on data.

19
Q

What is the purpose of React Fragments, and when would you use them?

A

React Fragments are used to group multiple JSX elements without introducing unnecessary parent DOM elements. They are particularly useful when you need to return multiple elements from a component’s render method without adding additional elements to the DOM structure. They improve code organization and performance.

20
Q

Describe the differences between React and React Native.

A

React is a JavaScript library for building user interfaces on the web, while React Native is a framework for building mobile applications for iOS and Android platforms.
React uses web technologies like HTML, CSS, and JavaScript to render user interfaces in web browsers, whereas React Native uses native components for mobile app development, resulting in a more native look and feel.
Code written in React can’t be directly used in React Native, as they have different components and rendering mechanisms. However, React and React Native share a similar component-based architecture and developer experience.
React Native allows developers to use React skills to build mobile apps, making it a popular choice for cross-platform development.