React Questions Flashcards

1
Q

What is React?

A

React is an JavaScript library for building dynamic and interactive web applications with a component-based architecture. React’s key features are that it is component based, uses a virtual DOM, uses declarative syntax, has a one-way data-flow and uses JSX.

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

What does component based mean in React?

A

React allows developers to build user interfaces by breaking them down into small, reusable components. Each component represents a part of the user interface and can have its own logic, state, and properties. This approach promotes modularity and makes it easier to manage and maintain complex applications.

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

What is a virtual DOM?

A

React uses a virtual representation of the actual DOM, known as the Virtual DOM. When the application’s state changes, React efficiently calculates the minimum number of changes required to update the actual DOM, which leads to better performance and faster rendering.

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

What is declarative syntax?

A

React follows a declarative programming style, where developers describe the desired state of the UI using JSX, and React takes care of rendering and updating the DOM to match that state. This approach simplifies the code and makes it easier to reason about the application’s behavior.

// A simple functional component using JSX to declare the desired UI
function Greeting(props) {
return <h1>Hello, {props.name}!</h1>;
}

// Usage of the component which React uses to update the DOM
const App = () => {
return <Greeting></Greeting>;
};

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

What is one-way data-flow?

A

React enforces a unidirectional data flow, where data flows in a single direction, from parent components to child components. This pattern helps to avoid data inconsistencies and makes the application easier to understand and debug.

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

What are alternatives to one-way data-flow?

A

Two-Way Data Binding:
Two-way data binding is a different approach to managing data between the user interface and the underlying data model. In this approach, changes to the model (data) automatically update the view (UI), and vice versa. This means that when the data changes in the model, the UI is updated to reflect the changes, and when the user interacts with the UI, the changes are propagated back to the data model.
Two-way data binding is commonly used in frameworks like AngularJS, where it simplifies the process of keeping the UI in sync with the underlying data. While it can make some tasks easier, it can also lead to more complex debugging and potential data inconsistency issues.

Unidirectional Data Flow with Centralized State Management:
This approach is similar to one-way data flow but introduces a centralized state management system, often called a state container or store. The state container holds the entire application state, and any changes to the state must happen through predefined actions.
Frameworks and libraries that follow this approach include Redux (used with React) and Vuex (used with Vue.js). The data flow in this pattern is unidirectional, where the application state is read-only, and all changes to the state are performed by dispatching actions. These actions trigger reducers that update the state, and then the updated state is reflected in the UI.

This approach simplifies the management of complex state interactions, as all state changes are funneled through a single source of truth (the state container). It also helps to maintain a clear history of state changes, which aids in debugging and understanding application behavior.

In summary, two-way data binding is an alternative to one-way data flow that allows data changes to flow in both directions between the model and the UI. Unidirectional data flow with centralized state management is another alternative where data flows in a single direction and is managed through a centralized state container. Each approach has its own set of benefits and trade-offs, and the choice of data flow mechanism depends on the specific requirements and complexity of the application.

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

What is JSX?

A

JSX is a syntax extension for JavaScript used with React. It allows developers to write UI components using a syntax that combines JavaScript and XML-like syntax. JSX makes the code more readable and enables a seamless integration of JavaScript logic and UI elements.

// A simple functional component using JSX
function Greeting(props) {
return <h1>Hello, {props.name}!</h1>;
}

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