React/Redux Flashcards
What is Redux?
Redux is a predictable state container for JavaScript applications. It is commonly used in front-end web development with frameworks such as React, Angular, and Vue. Redux is based on the Flux architecture and provides a centralized store for managing the state of an application.
The basic idea of Redux is to store the entire state of the application in a single object called the “store”. This store is immutable and can only be modified by dispatching actions. Actions are plain JavaScript objects that describe a change in the state of the application. They contain a “type” property that identifies the type of action and an optional “payload” property that provides additional data for the action.
What is a state in React and how is it used?
The state is a built-in React object that is used to contain data or information about the component. A component’s state can change over time; whenever it changes, the component re-renders.
Why can’t browsers read JSX?
Browsers can’t read JSX directly because it’s a syntax extension to JavaScript that is not recognized by browsers. JSX is a syntactic sugar for creating React elements that allows developers to write HTML-like code within their JavaScript files. However, browsers only understand JavaScript, HTML, and CSS, so they can’t parse JSX code directly.
In order to use JSX in a web application, developers must first compile their code using a build tool like Babel, which transforms the JSX code into regular JavaScript code that browsers can understand. Babel does this by parsing the JSX syntax and converting it into a series of function calls that create React elements. This transformed code can then be included in a web page like any other JavaScript code.
In Redux, what do you understand by “Single source of truth”?
In Redux, the “single source of truth” refers to the concept that the entire state of an application is stored in a single JavaScript object, called the store. This means that all of the data that represents the current state of the application is located in one place, making it easy to manage and access.
The state in Redux is immutable, meaning it cannot be directly modified. Instead, any changes to the state must be made by dispatching an action to the store. The store then updates its internal state based on the action, and triggers a re-render of the application UI based on the updated state.