Week 10 Quiz Questions Flashcards

1
Q

How do controlled components differ from uncontrolled components?

A

controlled components
uncontrolled components primarily use React states

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

What are some advantages of using uncontrolled components?

A

little less complex than controlled forms
ease of use

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

What are some advantages of using controlled components?

A

use of ‘state’ and renders
gives access to values via state, real-time

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

Which style do you prefer?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
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
6
Q

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

A

React Hook Form, Formik, and React Final Form

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

When would we want to create a list of React components?

A

When you want to display multiple, similar React components from a collection of data

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

Why is it important for React components to be data-driven?

A

data-driven components revolve around the data itself/ what is displayed, so the content/ data must be the most important thing

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

Where in the component code would a list of React components typically be built?

A

often, React list components will be created with the map() method and what is returned is the ul or li element at the end for where the list elements will go

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

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

A

map()

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

Why do components in a list need to have unique keys?

A

components in a list need unique keys so that if components in a array of data are moved, changed, get deleted, etc, the corresponding key will always know which data to refer to

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

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

A

0 indexed keys

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

What are two ways React components can interact?

A

passing properties from a parent component to children components, and by responding to Events from children components. (known as lifting state up)

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

How can multiple React components share state?

A

via lifting state to the closest parent

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

What are the steps to “lift state up”?

A
  1. Remove state from the child components.
  2. Pass hardcoded data from the common parent.
  3. Add state to the common parent and pass it down together with the event handlers.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

When would you want to lift state up?

A

multiple similar components that you may want to use elsewhere, so you have the parent give functionality rather than hardcoded into child component

17
Q

When is a component “mounted” to the DOM?

A

mounts first and then deals with data after mounting

18
Q

What is a React Effect?

A

Effects will happen after initial rendering of component that synchronizes with a component in an external system (API, etc)

19
Q

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

A

when you need to connect with some outside component, vs when you use states

20
Q

When do Effects run?

A

runs after initial rendering phase

21
Q

What function is used to declare an Effect?

A

useEffect()

22
Q

What are Effect dependencies and how do you declare them?

A

second argument in useEffect that ensures the useEffect knows when to change the dependencies???

23
Q

Why would you want to clean up from an Effect?

A

making a request and component mounts again, if they are diff or error, clean up prevents any unnecessary events from happening

24
Q

How do you clean up from an Effect?

A

use:
return (() => {}) or return any function

25
Q

When does the cleanup function run?

A

React will call your cleanup function each time before the Effect runs again, and one final time when the component unmounts (gets removed).

26
Q

What is the purpose of the Express Static middleware?

A

serves ‘static’ files from the specified root directory

27
Q

What does express.static() return?

A

returns a function

28
Q

What are several examples of static files?

A

imgs, javascript, css, html

29
Q

What is a good way to serve application images using Express?

A

via app = express()
app.use(express.static(rootDirectory))

30
Q

What does fetch() return?

A

A Promise that resolves to a Response object.

31
Q

What is the default request method used by fetch()?

A

the get request method

32
Q

How do you specify the request method (GET, POST, etc.) when calling fetch?

A

as the second argument in fetch()

33
Q

How does fetch report errors?

A

ok property of the response is set to false if the response isn’t in the range 200–299

34
Q

How can useEffect be used to load data for a component?

A

can load other data after component has been rendered

35
Q

What browser function can be used to make HTTP requests to a server in React?

A

fetch()

36
Q

How do you use useEffect to load component data just once when the component mounts?

A

second argument has empty brackets []

37
Q

How do you use useEffect to load component data every time the data key changes?

A

put data into dependency array (second argument in useEffect)

38
Q

In a large-scale production app, what are some better alternatives for loading and managing backend data?

A

React Query and Vercel SWR