React State Management Flashcards

1
Q

What is state management?

A

A way of maintaining and sharing data across components.

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

What is the primary way of managing state (v16.8+)?

A

The React hook useState.

E.g. const [name, setName] = useState('Anna')

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

What is the difference between local and global state?

A
  • Local: state accessible by a single component
  • Global: state accessible by any component within a component hierarchy
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is Redux Toolkit (RTK)?

A

A library specialised in global state management. RTK is the recommended way to implement Redux.

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

What is prop drilling?

A

When props are passed down through components that don’t need it until it reaches a child that does.

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

How can React manage state globally?

A

By using one of the following…
* the Context API
* an external library (e.g. Redux, MobX, Zustand)

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

What is an action?

A

An event that describes something that happened in the application. Implemeneted as a plain JavaScript object that has a type field.

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

What is a reducer?

A

A function that changes state by reducing a collection of actions by type.

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

When would you use useReducer (instead of useState)?

A

When a component deals with complex state, usually an array or object

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

Explain React’s built-in global state management feature.

A

It’s called the Context API and it can be used via useContext. First createContext and put a Provider at the top-level of the component hierarchy. Then access the context via useContext at the component level.

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