React Flashcards
What is React?
A JavaScript library for building UI
What is a React element?
An Object with properties representing a component
How do you mount a React element to the DOM?
You call the render
method off of the root
object (which could be a div you queried for) and pass in the created React element.
What is a React component?
Components are independent and reusable bits of code. They serve the same purpose as JavaScript functions, but work in isolation and return HTML.
How do you define a function component in React?
You name it with a capitalized first letter and have it return JSX
How do you mount a component to the DOM?
You call the render function on the root with the desired component being passed into it.
What are props in React?
They are the properties of the react element/component.
How do you pass props to a component?
You contain the props within curly ({props.propertyName}
) braces. Each function component can be passed exactly one props
object!
How do you write JavaScript expressions in JSX?
You would contain the expression within curly ({}
) braces.
(ex.) <p>2 + 2 is...{2+2}</p>
What are controlled components?
A component where the state controls/is the source of the input data
What two props must you pass to an input for it to be “controlled”?
value
and onChange
What Array method is commonly used to create a list of React elements?
Array.map() and Array.filter()
What is the best value to use as a “key” prop when rendering lists?
A unique identifier to the data (not based off say, index in array, due to possibility of data mutation)
What is a React Effect?
A section of code run after every render, mainly used to synchronize React with external systems.
When should you use an Effect and when should you not use an Effect?
When you need the React component to interact with a non-React system in some way one should use an Effect. One does not need an Effect if attempting to change data while rendering.