State Management Flashcards

1
Q

What is shared state in React?

A

State used by multiple components.

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

What are the downsides of using prop drilling?

A

Forces components in between to have unused props, works for few adjacent components, not ideal for distant components.

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

What is React Context used for?

A

Sharing state across components.

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

How is React Context created?

A

By using createContext, which requires a default value and has a generic type parameter.

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

What is the role of the Provider in React Context?

A

It supplies the context to child components.

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

How do you create a context in React?

A

const SomeContext = createContext<ContextType>(defaultValue);

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

How does a Provider component work in React Context?

A

It wraps child components and provides the context value using the SomeContext.Provider.

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

How is the useContext hook used in React?

A

It consumes context values by passing context into useContext and destructuring properties.

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

What is the syntax to access context values using useContext?

A

const { someState } = useContext(SomeContext);

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

How do you use context in a component?

A

By using useContext to access and display context values, like { someState }.

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