React.js Flashcards

1
Q

What is React?

A

React is a JavaScript library for building user interfaces

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

What are the key features of React?

A

Key features include component-based architecture

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

Explain the difference between functional and class components

A

Functional components are JavaScript functions that return React elements. Class components are ES6 classes that extend React.Component and have a render method. Functional components with hooks are now preferred over class components.

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

What are React Hooks?

https://www.youtube.com/watch?v=TNhaISOUy6Q

A

Hooks are functions that let you use state and other React features in functional components without writing a class. Examples include useState

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

What is the useState Hook?

A

useState is a Hook that lets you add state to functional components. It returns an array with the current state value and a function to update it.

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

Explain the useEffect Hook

A

useEffect lets you perform side effects in functional components. It runs after every render and can be used for data fetching

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

What is the difference between props and state?

A

Props are read-only and passed from parent to child components. State is mutable and managed within the component itself. Props are immutable

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

What is JSX?

A

JSX is a syntax extension for JavaScript that looks like HTML and makes it easier to write and add HTML in React. It gets transformed to regular JavaScript function calls.

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

What is the virtual DOM?

A

The virtual DOM is a lightweight copy of the actual DOM. React uses it to improve performance by minimizing direct manipulation of the DOM and efficiently updating only the necessary parts.

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

Explain the React component lifecycle

A

The React lifecycle is divided into three main phases:

Initialization phase: This is the stage where the component is constructed with the given Props and default state. This is done in the constructor of a Component Class.
Mounting Phase: This phase begins when a component is created and inserted into the DOM.
Updating Phase: This occurs when a component is re-rendered due to changes in props or state.
Unmounting Phase: This is the final phase when a component is removed from the DOM.

The component lifecycle consists of mounting (adding to the DOM)

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

What is prop drilling? How can you avoid it?

A

Prop drilling occurs when props are passed through multiple levels of components. It can be avoided using Context API

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

What is the Context API?

A

Context provides a way to pass data through the component tree without manually passing props at every level. It’s an alternative to prop drilling.

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

How do you handle forms in React?

A

Forms can be controlled by storing form data in component state and updating it with onChange handlers. React uses synthetic events to handle form submissions.

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

What is the difference between controlled and uncontrolled components?

A

Controlled components have their state managed by React

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

What is the purpose of useReducer Hook?

A

useReducer is an alternative to useState for complex state logic. It’s preferable when you have multiple sub-values or when the next state depends on the previous one.

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

Explain React.memo

A

React.memo is a higher-order component that prevents unnecessary re-renders of functional components by doing a shallow comparison of props.

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

What is the key prop in React lists?

A

The key prop helps React identify which items have changed

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

How does React handle performance optimization?

A

React uses techniques like virtual DOM

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

What is the useCallback Hook?

A

useCallback returns a memoized version of a callback function that only changes if one of the dependencies has changed.

20
Q

Explain the useMemo Hook

A

useMemo returns a memoized value that only recomputes when one of its dependencies changes

21
Q

What are custom Hooks?

A

Custom Hooks are JavaScript functions that start with ‘use’ and can call other Hooks. They allow you to extract component logic into reusable functions.

22
Q

How do you handle side effects in React?

A

Side effects are handled using the useEffect Hook. This can include data fetching

23
Q

What is the useContext Hook?

A

useContext provides a way to consume context in a functional component without wrapping the component in a Context.Consumer.

24
Q

Explain the concept of lifting state up

A

Lifting state up means moving the state to a common ancestor component when multiple components need to share the same changing data.

25
Q

What are error boundaries in React?

A

Error boundaries are React components that catch JavaScript errors anywhere in their child component tree

26
Q

How do you do conditional rendering in React?

A

Conditional rendering can be done using JavaScript operators like if

27
Q

What is the difference between React and React Native?

A

React is for web development

28
Q

Explain the useRef Hook

A

useRef returns a mutable ref object that persists for the full lifetime of the component. It’s often used to access DOM elements directly.

29
Q

What is prop types?

A

Prop types is a way to check the types of props in React components to catch bugs early. It’s typically used with the ‘prop-types’ library.

30
Q

What is the difference between createElement and cloneElement?

A

createElement creates a new React element

31
Q

How do you pass data between components?

A

Data can be passed between components using props

32
Q

What is the purpose of the React.Fragment?

A

React.Fragment lets you group multiple elements without adding an extra DOM node to the rendered HTML.

33
Q

Explain server-side rendering in React

A

Server-side rendering involves rendering React components on the server and sending the fully rendered page to the client

34
Q

What is code splitting in React?

A

Code splitting is a technique to split your code into smaller chunks and load them on demand

35
Q

How do you optimize performance in a React application?

A

Techniques include using React.memo

36
Q

What is the purpose of the useImperativeHandle Hook?

A

useImperativeHandle customizes the instance value that is exposed when using ref on a child component.

37
Q

Explain the difference between state and props

A

State is internal and controlled by the component itself

38
Q

What are Higher-Order Components (HOC)?

A

HOCs are functions that take a component and return a new component with additional props or behavior.

39
Q

How do you handle routing in React?

A

Routing is typically handled using libraries like React Router

40
Q

What is the purpose of the useLayoutEffect Hook?

A

useLayoutEffect is similar to useEffect

41
Q

Explain React portals

A

Portals provide a way to render children into a DOM node that exists outside the DOM hierarchy of the parent component.

42
Q

What is the use of the useDebugValue Hook?

A

useDebugValue is used to display a label for custom hooks in React DevTools.

43
Q

How do you test React components?

A

React components are typically tested using libraries like Jest and React Testing Library

44
Q

What is the difference between deep and shallow rendering?

A

Shallow rendering renders only the component being tested without rendering child components

45
Q

Explain the React.lazy and Suspense

A

React.lazy allows dynamic imports of components