React-State Flashcards
What are hooks in React?
Hooks are special functions that act as unconditional statements that your component needs
What are the “Rules of Hooks”? (if necessary, re-read the “Pitfall” box in State)
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
What is the purpose of state in React?
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
Why can’t we just maintain state in a local variable?
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.
What two actions happen when you call a state setter function?
a state setter function updates a local variable and triggers react to render the component again
When does the local state variable get updated with the new value?
After the setter function is called.