React/Redux Flashcards

1
Q

Differentiate between the Real DOM and the Virtual DOM

A

Real DOM:
- Creates a new DOM if an element updates

Virtual DOM:
- The virtual DOM is like a blueprint. It contains all the details needed to construct the DOM, and can be changed easily. Fast because React figures out the difference between the virtual DOM and the real DOM to get the two trees to match

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

What is React?

A
  • React is a front-end JavaScript library
  • Follows component-based approach to build reusable UI components
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Advantages of React

A
  • Uses virtual DOM to increase application performance
  • More readable due to JSX
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Limitations of React

A
  • The library is very large, not only in dependencies but in complexity, takes a long time to master
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is JSX?

A

JSX is a JavaScript syntax extension that allows you to write HTML tags directly in your JavaScript code

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

What is JSX?

A

JSX is a JavaScript syntax extension that allows you to write HTML tags directly in your JavaScript code

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

Explain how the Virtual DOM works

A

Whenever there is a change, React compares the virtual DOM to the Real DOM in order to calculate what changes need to be made to the Real DOM, and will update only the things that need to be changed.

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

What are props?

A

Props are passed down from parent to child components throughout the React app, such as variables/data. (Generally used to render dynamic data).

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

Explain the lifecycle methods of React components

A

componentDidMount: Executed on client side after first render
componentDidUpdate: Called right after rendering takes place
componentWillUnmount: Called after component is unmounted from the DOM

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

How do lifecycle methods work in React functional components?

A

The useEffect hook works similarly to the three lifecycle methods: componentDidMount (initial render), componentDidUpdate (dependency array), and componentWillUnmount (cleanup function).

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

Controlled components vs uncontrolled components

A

Controlled components:
- Do not maintain their own state
- Data is controlled by the parent component
- Take in current values through props and then notify the changes via callbacks

Uncontrolled components:
- Maintain their own state
- Data is controlled by the DOM

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

What is a higher order component?

A

Higher-order-component (HOC) is a function that takes a component and returns a new component.

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

What can you do with higher order components?

A

Reuse code, and abstract state away

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

What is the significance of keys in React?

A

The main purpose of keys is to help React differentiate and distinguish elements from each other. It helps React identify what elements have changed/added/removed.

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

What is Redux?

A

Redux is a predictable state container for JavaScript applications and is used for managing the application’s state

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

What are the 3 principles that Redux follows?

A
  1. Single source of truth: State of the entire app is stored in an object.
  2. State is read-only: The only way to change the state is to trigger an action. An action is a POJO describing the change
  3. Changes are made with pure functions: Pure functions are those whose return value depends solely on the values of their arguments.
16
Q

What are the 3 principles that Redux follows?

A
  1. Single source of truth: State of the entire app is stored in an object.
  2. State is read-only: The only way to change the state is to trigger an action. An action is a POJO describing the change
  3. Changes are made with pure functions: Pure functions are those whose return value depends solely on the values of their arguments.
17
Q

What does single source of truth mean?

A

In React-Redux applications, when your Redux is a single source of truth, it means that the only way to change your data in UI is to dispatch redux action which will change state within redux reducer. And your React components will watch this reducer and if that reducer changes, then UI will change itself too. But never other way around, because Redux state is single source of truth.

17
Q

What does single source of truth mean?

A

In React-Redux applications, when your Redux is a single source of truth, it means that the only way to change your data in UI is to dispatch redux action which will change state within redux reducer. And your React components will watch this reducer and if that reducer changes, then UI will change itself too. But never other way around, because Redux state is single source of truth.

18
Q

How does data flow through Redux?

A
  • Follows a unidirectional flow of data.
  1. An action is dispatched when a user interacts with the app.
  2. The root reducer is called with the current state and the dispatched action.
  3. The subscribed components rerender when the store changes
19
Q

What is an action in Redux?

A

Actions in Redux are an object that have a type property that indicates what type of action is being performed.

20
Q

What is a reducer in Redux?

A

Reducers are pure functions that specify how the application’s state changes in response to an action. It returns a NEW state.

21
Q

Advantages of Redux?

A
  • Very predictable, as there is one source of truth
  • Maintainable, as it is predictable