State a component memory Flashcards

1
Q

What is a state variable used for in a component?

A

To remember some information between renders.

State variables store data that can change over time within a component.

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

How are state variables declared in React?

A

By calling the useState Hook.

The useState Hook is a built-in function that allows you to add state to functional components.

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

What are Hooks in React?

A

Special functions that start with use, allowing you to hook into React features like state.

Common hooks include useState, useEffect, and useContext.

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

Where must Hooks be called in a React component?

A

At the top level of a component or another Hook.

Hooks should not be called conditionally or inside loops.

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

What does the useState Hook return?

A

A pair of values: the current state and the function to update it.

This allows for both reading and updating the state in the component.

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

Can you have more than one state variable in a React component?

A

Yes, you can have more than one state variable.

React matches them up by their order of declaration.

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

Is state private to a component in React?

A

Yes, state is private to the component.

Each instance of a component maintains its own state.

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