React Flashcards
What is React?
React is a JavaScript library for building User Interfaces. It is not a framework.
What is React responsible for?
React is only responsible for the View layer.
How do you install React?
Install react with npm install react
How do you put React into a file?
Import React in every file you need it with import React from “react”
What is a React Element?
- A React Element is the smallest building block. It’s a representation of a small piece of your UI.
- React.createElement returns a React Element:
React.createElement(type, options, children)
What is ReactDOM?
ReactDOM is the glue between React and the DOM. ReactDOM is separate from React because you can write React for native applications.
What is reconciliation?
Reconciliation is the process of syncing the Virtual DOM to the actual DOM.
How do you install ReactDOM?
- Install ReactDOM with npm install react-dom
- Import ReactDOM’s createRoot method with import {createRoot} from “react-dom/client”
- The root element is where ReactDOM will render your UI
createRoot(root).render(element);
What manages the root element?
- ReactDOM completely manages the root element
- Apps built with React have a single root element (The most common use case)
What is JSX?
- JSX is a special syntax for React that makes it easier to represent your UI
- JSX looks similar to HTML but it is not HTML
- JSX code you write gets transformed into React.createElement
- JSX is not part of your browser. You need a tool to transform it into valid JavaScript.
- A JSX element is an object.
- You can treat a JSX element like an object.
- You can assign a JSX element to a variable.
- You can return a JSX element from a function.
How do attributes get passed in JSX?
- Attributes in JSX get passed as the 2nd argument of React.createElement(…)
- <div></div>is how you would give the class active to this element.
- You need quotes around attribute values that are strings.
What is an expression?
- An expression is any valid JavaScript code that resolves to a value
- Expressions in JSX need to be wrapped inside curly braces: {expression}
<h1>You have {2 + 3} notifications</h1>
is an example of JSX with an expression.
What is a React Component?
- A React Component is a function that returns one React Element describing a section of the UI.
- Components defined with a function are called function components.
- React Components promote code reuse and are easier to debug.
- A React Component’s name has to start with an uppercase.
- Use UpperCamelCase when naming React Components
What are props?
- Props is short for properties.
- Props is an object received as the first argument of a Component.
- Attributes on Components get converted into an object called Props.
- Props make components more reusable.
What are children?
- props.children represents the content between the tags of a Component.
- props.children can be an array or a single item.
- props.children can contain text and/or React Elements and/or React Components.