React Flashcards

1
Q

What is React?

A

A JavaScript library for building UI

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a React element?

A

An Object with properties representing a component

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you mount a React element to the DOM?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a React component?

A

Components are independent and reusable bits of code. They serve the same purpose as JavaScript functions, but work in isolation and return HTML.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you define a function component in React?

A

You name it with a capitalized first letter and have it return JSX

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you mount a component to the DOM?

A

You call the render function on the root with the desired component being passed into it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are props in React?

A

They are the properties of the react element/component.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you pass props to a component?

A

You contain the props within curly ({props.propertyName}) braces. Each function component can be passed exactly one props object!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you write JavaScript expressions in JSX?

A

You would contain the expression within curly ({}) braces.
(ex.) <p>2 + 2 is...{2+2}</p>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are controlled components?

A

A component where the state controls/is the source of the input data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What two props must you pass to an input for it to be “controlled”?

A

value and onChange

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What Array method is commonly used to create a list of React elements?

A

Array.map() and Array.filter()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the best value to use as a “key” prop when rendering lists?

A

A unique identifier to the data (not based off say, index in array, due to possibility of data mutation)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a React Effect?

A

A section of code run after every render, mainly used to synchronize React with external systems.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

When should you use an Effect and when should you not use an Effect?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

When do Effects run?

A

After the component mounts to the DOM, or when one of the dependencies changes.

17
Q

What function is used to declare an Effect?

A

useEffect(fn, [dependencies]) with dependencies being optional

18
Q

What are Effect dependencies and how do you declare them?

A

They are declared in the useEffect function call as the second argument. They allow the effect to only be run when certain values passed as a dependency change.

19
Q

How do you clean up from an Effect?

A

You would return a function that undoes what the effect did, such as returning a clearInterval after setting one in the Effect.

20
Q

When does the cleanup function fire?

A

Before the effect runs the next time and during the unmount.