React Flashcards
What is React?
React is an open-source JavaScript frontend library for creating user interfaces. It uses component based approach to create interactive web and mobile user interfaces.
What are the advantages of React?
First is the increased performance with Virtual DOM. React is insanely fast.
Second, React uses JSX that makes code painless to read and write.
Third, it uses components, making it easier to pass state and data
What is JSX?
JSX is a syntax extension to JavaScript that describes what the UI should look with the full power of JavaScript.
What is the difference between Element and Component?
React elements are the building blocks of React applications.
It describes what you want to see on the screen. React elements are immutable.
React components are small, reusable pieces of code that return a React element to be rendered to the page. The simplest version of React component is a plain JavaScript function that returns a React element. Components can also be ES6 classes.
You can say that a component is a factory for creating multiple elements.
What are react fragments?
Fragments let you group a list of children without adding extra nodes to the DOM because fragments are not rendered to the DOM.
This is also very useful for CSS Flexbox and Grid as they have special parent to child relationship as adding an extra tag in the between will break the layout.
What is prop in React?
Props or properties are arguments passed into React components. It contains data coming down from a parent component to a child component.
What is state in React?
State is used to store data that might change during the lifetime of a component. This data can include user input, the results of API calls, or any other data that should be reflected in the user interface.
Component Re-rendering: When the state of a component changes, React automatically re-renders the component to reflect the updated state. This is one of the core principles of React: a component’s UI is a function of its state.
Why should we not update the state directly?
Updating the state directly, like below will not cause the component to re-render.
Instead, use setState() method. This method will schedule an update to a component’s state object. When state changes, the component responds by re-rendering.
What are Controlled and Uncontrolled Component.
A Controlled Component is one that takes a value through props and notify changes through callbacks like onChange or onClick.
Form data is handled by React component.
Uncontrolled Component is one that stores its own state internally, and queries the DOM using a ref or reference to find the current value when it is needed.
Form data is handled by the DOM.
In most cases, Controlled components are recommended to be used when implement forms.
What is Virtual DOM?
A virtual DOM object is a representation of a DOM object, like a lightweight copy.
Once the virtual DOM has been updated, then React compares the virtual DOM with a virtual DOM snapshot that was taken right before the update.
By comparing the new virtual DOM with a pre-update version, React figures out exactly which virtual DOM objects have changed. This process is called “diffing.”
Once React knows which virtual DOM objects have changed, then React updates those objects, and only those objects, on the real DOM.
What is JavaScript?
JavaScript is a programming language that is mainly used on the client side, meaning it runs in the user’s web browser. This enables it to manipulate the Document Object Model (DOM), making web pages interactive and responsive.
What is the DOM
The Document Object Model (DOM) represents an HTML or XML document as a tree structure of objects and nodes. This tree structure allows web developers to access and manipulate the content, structure, and style of a web page using programming languages like JavaScript.
Key points about the DOM:
Tree Structure: The DOM organizes the document’s elements (such as HTML tags) into a tree structure. Each element is represented as a node in the tree.
Objects and Nodes: Elements and attributes of a document are represented as objects and nodes in the DOM. These objects and nodes can be accessed and modified programmatically.
API: The DOM provides an API (Application Programming Interface) for interacting with web documents. Web developers can use JavaScript to access and manipulate the DOM to change the content, structure, and appearance of a web page.
Event Handling: The DOM allows for the registration of event handlers that respond to user interactions (e.g., clicks, mouse movements) and can trigger JavaScript functions.
Dynamic Interactivity: With the DOM, web pages can be made interactive, enabling dynamic updates, form validation, and other behaviors.
What is HTTP
Hypertext Transfer Protocol.
HTTP follows a request-response model. A client (usually a web browser) sends an HTTP request to a web server, which processes the request and sends back an HTTP response containing the requested data.
Common HTTP methods include GET (retrieve data), POST (submit data), PUT (update data), and DELETE (remove data).
What is Async and await
An async function always returns a Promise.
The await keyword is used inside an async function to pause the execution of the function until a Promise is resolved.
What is react native
React Native allows developers to create mobile apps for iOS and Android platforms with a single codebase, making it a popular choice for cross-platform mobile app development.