React-State Flashcards

1
Q

What are hooks in React?

A

Hooks are special functions that act as unconditional statements that your component needs

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

What are the “Rules of Hooks”? (if necessary, re-read the “Pitfall” box in State)

A

Hooks can only be called at the top level of your component. Meaning that you cannot call Hooks inside conditions, loops, or other nested functions

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

What is the purpose of state in React?

A

The purpose of state in React is to allow components to remember certain things about the component: the current input value, the current image, the shopping cart

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

Why can’t we just maintain state in a local variable?

A

Local variables don’t persist between renders of a component. When a component renders a second time it does so from scratch and changes to local variables are not remembered.

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

What two actions happen when you call a state setter function?

A

a state setter function updates a local variable and triggers react to render the component again

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

When does the local state variable get updated with the new value?

A

After the setter function is called.

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