Week 11 Quiz Questions Flashcards

1
Q

What is the purpose of React “context”?

A

allows the parent component to pass down information directly to a child without props

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

What values can be stored in context?

A

any type of values, typically objects, but can be functions or other things

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

How do you create context and make it available to the components?

A

context created first by importing { createContext } from react and then exporting a variable (if on a diff file) const someContext = createContext()

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

How do you access the context values?

A

in the child component, use useContext and pass to it the createContext previously created
you assign to it the property given from the parent component and passed down via the Context.Provider
wrapping the main app.js components in Context.provider

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

When would you use context? (in addition to the best answer: “rarely”)

A

when you want to directly pass something down to a child that is far away– this avoids prop drilling which can be a lot of writing code in different layers just to get one thing to a distant child

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

What is a React custom hook?

A

custom function that allows you to pass functionality down to other areas

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

When are custom hooks useful? When are they not required?

A

useful for organizing functionality

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

What is the syntax (or naming convention) for writing a custom hook?

A

useCustomStateName()

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

How do you call a custom hook?

A

like any other function (must be imported)

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

When do custom hooks execute?

A

on call

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