React Flashcards

1
Q

What is React?

A

React is a JS library for building UI.

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

What is Redux?

A

Redux is a predictable state container for JS apps. Meaning it is a state management library.

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

How does Redux work?

A

Redux works by creating a store, which acts as the centralized point that stores state for an application in a global sense, by wrapping the app component allowing access to all child components within the app. In order to update the state, an action must be called. An action is an object that is created by an action creator that has to contain a type of action and optionally a payload which would describe new data to update the state. The action is then passed to a reducer, which takes in the original state as well as the action then reduces the two down to create a new instance of the state with the update.

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

What makes Redux so special?

A

What makes Redux special is the fact that it can be used by different JS frameworks and because it is predictable in its functionality. Meaning that when the same state and action are passed to a reducer, the same result is always produced because reducers are pure functions.

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

Describe the Redux setup process.

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

How do reducers work in Redux?

A

Reducers work by taking in the old state and the action that was dispatched. The reducer then checks the type of action dispatched and will run the corresponding function. The original state is copied then updated with any new or updated data contained within the action.payload object if available or returns the new updated state as described within the function.

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

Why did you choose React?

A

I chose React because when I was first exploring which framework to learn, React already had a very positive standing in the web dev community and it seemed to be rapidly growing in popularity. What stood out to me when I initially jumped into the React docs was how straightforward all the React concepts were; such as how state was managed and updated and how that in turn will update the UI. I also really liked how intuitive JSX components are and how it can make breaking down components of a feature very easy. Because of how easy it was to learn, it made creating my own projects much easier and quicker.

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

What are the major features of React?

A

The major features of React are JSX, Virtual DOM, one-way data binding, improved performance, many extensions, conditional rendering, reusable components.

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

What is JSX?

A

JSX is a javascript syntax extension that allows for writing HTML in javascript.

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

What is the Virtual DOM and how does it work?

A

The Virtual DOM is a complete copy of the DOM. The Virtual DOM works by updating before the DOM when a modification is made to a web app then finds the difference between the DOM and the Virtual DOM then updates the parts of the DOM that are different. This increases performance as it is only rendering small chunks that need updating instead of the entire DOM.

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

What is state in React?

A

React state is a built-in React object that is used to contain data or information about the component.

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

What are props in React?

A

Props is a special keyword in React that stands for properties and is used for passing data from one component to another. Data with props are passed in a unidirectional flow from parent to child.

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

What is the difference between state and props?

A

State is used to store the data of a component that has to be rendered to view. State data can be changed over time. State can only be used in class components. Event handlers generally update state.

Props are used to pass data and event handlers to child components. Props are immutable. Props can be used in both functional and class components. Parent components sets props for the children components.

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

What does lifting state up mean and why do we do it?

A

Lifting state means moving state management from child components to a “common ancestor”. This is done to share state between multiple components using props and helps keep components in sync when data changes.

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

Why do we set up a key property when we map over an array in React?

A

Keys are used to uniquely identify a component instance in the list. This helps React optimize re-rendering by recycling existing components by determining which items have changed, are added, or are removed. This means that instead of re-rendering the entire list, React can simply re-render the specific components that have changed.

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

What are core principles in React?

A

The core principles of React are: JSX, class and function components, props, state, lifecycle methods, and hooks.

17
Q

How does React use closures?

A

React uses closures uses closures all the time when using functional components. Many functional components will have event listeners and those event listeners will often change the state in some ways. So, those event listeners will have access to whatever state or props inside of the function component.

18
Q

What are the differences between React context and Redux?

A

The main difference between React context and Redux is in usage and the scale of management scope. React context is best used for managing smaller-scale states whereas Redux is best for scenarios necessitating complex state management shared across the entire application.

Some additional differences:

Data Flow - Redux is unidirectional and transfers data via Actions, Reducers, Dispatch, Selectors and other methods. This ensures that state is predictable and traceable making it easier to understand and debug. Context is simpler and more direct. It allows sharing data without the need for prop drilling. However, it does not have built-in mechanisms for managing complex state changes.

Philosophy - Redux acts as a single source of truth for application state, making it easier to manage and reason about state changes. Context allows each component to manage its own state or consume state from a shared context.

Usage - Redux manage shared state across multiple components in a large application. Context is suitable for managing component-specific states or sharing global data in a smaller app.