React.js fundamentals Flashcards
What is JSX in React?
JSX is a JavaScript Extension Syntax used in React to easily write HTML and JavaScript together.
How does the browser handle JSX code, and what tool can you use to make it work?
The browser doesn’t understand JSX because it’s not valid JavaScript. To make it work, JSX code needs to be transpiled using tools like Babel, which converts JSX into regular JavaScript code.
What does JSX code get converted to by Babel?
JSX code gets converted into a series of React.createElement calls, which are JavaScript function calls that create and describe React elements.
What is the syntax of React.createElement?
React.createElement(type, [props], […children])
Why was React.Fragment introduced in React 16.2?
React.Fragment was introduced to allow developers to group multiple adjacent JSX elements without adding extra DOM nodes to the structure. This helps avoid unnecessary div tags or other wrappers.
How can you add comments in JSX?
You can add comments in JSX using {/* /} inside curly braces, like this: {/ This is some text*/}.
Can you include JavaScript code within JSX? If so, how?
Yes, you can include JavaScript code within JSX by placing it inside curly braces { }. You can only use expressions that evaluate to a value, known as JSX Expression Syntax.
Which values are not displayed on the UI when used inside JSX?
Undefined, null, and boolean values are not displayed on the UI when used inside JSX, as they are treated as if they were not there
Why is className used instead of class for adding a class attribute in JSX?
className is used in JSX instead of class because class is a reserved keyword in JavaScript. Accessing props.class would result in an error.
In React, how are attribute names typically written?
In React, attribute names are typically written in camelCase, such as onClick instead of onclick.
X define the structure and behavior of parts of the user interface. They encapsulate reusable pieces of UI, making it easier to manage and render complex interfaces. What is X?
React components
What is the primary purpose of React DOM?
The primary purpose of React DOM is to render React components into the Document Object Model (DOM) of a web page. This allows developers to interact with and manipulate the web page’s structure and content.
What are controlled components in React, and why are they used?
Controlled components are React components that manage form elements and their corresponding data by synchronizing the component’s state with user input. They are used to ensure that React controls the input’s value based on the component’s state.
What are the key characteristics (3) of controlled components in React?
- state control
- event handling (e.g., onChange)
- maintaining a single source of truth for input values.
What is the concept of “lifting state up” in React?
In React, “lifting state up” refers to the practice of removing state from multiple components and moving it to their closest common parent. This allows you to manage the state centrally and pass it down to child components via props.