The building blocks of a React app are components. Components are reusable pieces of code that return a React element to be rendered to the page.
An HTML element represents a part of the web page, while a React component is a JavaScript function or class that optionally accepts inputs and returns a React element.
JSX is a syntax extension for JavaScript that resembles HTML. We use it in React to write HTML-like code, which is then transformed into lightweight JavaScript objects.
JavaScript expressions can be embedded in JSX by wrapping the expression in curly braces. For example,
{2 + 2}
in JSX would evaluate to4
.
No, React and JSX do not have any special features for iteration or conditional logic. They utilize standard JavaScript for these operations, such as map for iteration and ternary operators for conditional logic.
React responds to user inputs by using event handlers. These are functions that are triggered when a specific event, like a click or key press, occurs.
The word “use” in a function name, like useState or useEffect, indicates that a React component manages data with a Hook.
Two React components can share data through “props”, which allow for data to be passed from a parent component to a child component.
The three steps of refreshing a React UI are: render (where React generates a new tree of React elements), compare (React compares this new tree to the old one), and update (React updates the DOM to match the new tree).
After the initial render, updates can be triggered in a component by calling a state setter function, which is provided by the useState Hook.
No, React does not recreate DOM nodes on every re-render. Instead, it only updates the parts of the DOM that changed from the previous render.
After React has updated the DOM, the browser needs to paint these changes to the screen before the user can see them.
Keep these pages handy - they answer questions that show up regularly for this lab.