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.