React 230327 Flashcards

(36 cards)

1
Q

What is React?

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

What is a React element?

A

a component (see what component is)

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

this means to attach/insert a component into the dom tree

you mount by calling:
ReactDOM.render(foo, domContainer);

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

What is JSX?

A

a way to write html in react

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

How does React use JSX to render components?

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

What is a React component?

A

a JavaScript function that you can sprinkle with markup

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

How do you define a component in React?

A

In the return statement of a function whose name is capitalized, and which can be exported

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

How do you mount a component to the DOM (or “render” a component)?

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

What are props in React?

A

a way to pass info using what in html is like an attribute

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

How do you use props in a component?

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

How do you pass props to a component?

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

How do you write JavaScript expressions in JSX?

A

within curly braces

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

What are hooks in React?

A

a function starting with “use” then an uppercase letter,

e.g. useState

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

What are the “Rules of Hooks”? (if necessary, re-read the “Pitfall” box in State)

A

-declare at top

-don’t use inside conditionals/loops

-use “use”

-can only be called in react components and other hooks

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

What is the purpose of state in React?

A

it holds the data between function calls

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

Why can’t we just maintain state in a local variable?

A

because it would be reset when funcion calls

17
Q

What two actions happen when you call a state setter function?

A

-triggers react to re-render

-it keeps a cashe of state value

18
Q

When does the local state variable get updated with the new value?

A

on the re-render

19
Q

How do controlled components differ from uncontrolled components?

A

if it’s controlled, the parent

if it’s uncontrolled, … ?

20
Q

What are some advantages of using uncontrolled components?

A

don’t have to use state,

it’s simpler!

21
Q

What are some advantages of using controlled components?

A

it’s simpler to get the values out

22
Q

Which style do you prefer?

A

“it’s really just a preference”

23
Q

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

A

value and …

on change?

24
Q

What are some popular npm packages for creating forms in React?

25
Where in the component code would a list of React components typically be built?
inside the function body
26
What Array method is commonly used to create a list of React components?
map()
27
Why do components in a list need to have unique keys?
when there are changes to list item content, you need to know which one to edit!
28
When is a component "mounted" to the DOM?
When the page renders (when the component appears for the first time) and if a dependency changes
29
What is a React Effect?
lets you synchronize a component with an external system. when dependencies (reactive values) change, code runs. if you don't specify dependencies, all reactive values will be considered dependencies. *double check this part (above) when components and children are rendered, useEffect runs
30
When should you use an Effect and when should you not use an Effect?
If your Effect only adjusts some state based on other state, you might not need an Effect. In this case, try to use
31
When do Effects run?
when dependencies (reactive values) change, Effects runs. if you don't specify dependencies, all reactive values will be considered dependencies.
32
What function is used to declare an Effect?
useEffect()
33
What are Effect dependencies and how do you declare them?
when these dependencies run, effects run. they are declared as the second argument
34
Why would you want to clean up from an Effect?
to release resources that have been allocated inside useEffect. that is, to stop wasting resources
35
How do you clean up from an Effect?
36
When does the cleanup function run?
when the compoment is dismounted, before the effect is called again