Week 10 Quiz Questions Flashcards
How do controlled components differ from uncontrolled components?
controlled components
uncontrolled components primarily use React states
What are some advantages of using uncontrolled components?
little less complex than controlled forms
ease of use
What are some advantages of using controlled components?
use of ‘state’ and renders
gives access to values via state, real-time
Which style do you prefer?
What two props must you pass to an input for it to be “controlled”?
value and onChange
What are some popular npm packages for creating forms in React?
React Hook Form, Formik, and React Final Form
When would we want to create a list of React components?
When you want to display multiple, similar React components from a collection of data
Why is it important for React components to be data-driven?
data-driven components revolve around the data itself/ what is displayed, so the content/ data must be the most important thing
Where in the component code would a list of React components typically be built?
often, React list components will be created with the map() method and what is returned is the ul or li element at the end for where the list elements will go
What Array method is commonly used to create a list of React components?
map()
Why do components in a list need to have unique keys?
components in a list need unique keys so that if components in a array of data are moved, changed, get deleted, etc, the corresponding key will always know which data to refer to
What is the best value to use as a “key” prop when rendering lists?
0 indexed keys
What are two ways React components can interact?
passing properties from a parent component to children components, and by responding to Events from children components. (known as lifting state up)
How can multiple React components share state?
via lifting state to the closest parent
What are the steps to “lift state up”?
- Remove state from the child components.
- Pass hardcoded data from the common parent.
- Add state to the common parent and pass it down together with the event handlers.
When would you want to lift state up?
multiple similar components that you may want to use elsewhere, so you have the parent give functionality rather than hardcoded into child component
When is a component “mounted” to the DOM?
mounts first and then deals with data after mounting
What is a React Effect?
Effects will happen after initial rendering of component that synchronizes with a component in an external system (API, etc)
When should you use an Effect and when should you not use an Effect?
when you need to connect with some outside component, vs when you use states
When do Effects run?
runs after initial rendering phase
What function is used to declare an Effect?
useEffect()
What are Effect dependencies and how do you declare them?
second argument in useEffect that ensures the useEffect knows when to change the dependencies???
Why would you want to clean up from an Effect?
making a request and component mounts again, if they are diff or error, clean up prevents any unnecessary events from happening
How do you clean up from an Effect?
use:
return (() => {}) or return any function