React-Context Flashcards

1
Q

What is the purpose of React “context”?

A

Context lets the parent component make some information available to any component in the tree below it—no matter how deep—without passing it explicitly through 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

but you could pass any kind of value (even an object)

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

you assign the createContext() function to a variable and pass it a default value and then to make it available to a component, you have to use the useContext hook and pass it the variable with createContext() assigned to it.

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

You have to wrap the components with a context provider. This tells react that if any component inside the parent component asks for the context, give them this level.” The component will use the value of the nearest <LevelContext.Provider> in the UI tree above it.</LevelContext.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 have a compontent nested deep inside a component tree that you want to provide specific values to without having to pass the value down as a prop through many components

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