React-State Flashcards

1
Q

What are hooks in React?

A

Hooks are special functions that are only available while React is rendering. They let you “hook into” different React features

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 or your own Hooks. Cannot be called within 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

state allows React to remember information between renders

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 and changes to a local variable wont trigger renders

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

it can update the state variable and trigger 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

whenever useState is called

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