React 230327 Flashcards
(36 cards)
What is React?
What is a React element?
a component (see what component is)
How do you mount a React element to the DOM?
this means to attach/insert a component into the dom tree
you mount by calling:
ReactDOM.render(foo, domContainer);
What is JSX?
a way to write html in react
How does React use JSX to render components?
What is a React component?
a JavaScript function that you can sprinkle with markup
How do you define a component in React?
In the return statement of a function whose name is capitalized, and which can be exported
How do you mount a component to the DOM (or “render” a component)?
What are props in React?
a way to pass info using what in html is like an attribute
How do you use props in a component?
How do you pass props to a component?
How do you write JavaScript expressions in JSX?
within curly braces
What are hooks in React?
a function starting with “use” then an uppercase letter,
e.g. useState
What are the “Rules of Hooks”? (if necessary, re-read the “Pitfall” box in State)
-declare at top
-don’t use inside conditionals/loops
-use “use”
-can only be called in react components and other hooks
What is the purpose of state in React?
it holds the data between function calls
Why can’t we just maintain state in a local variable?
because it would be reset when funcion calls
What two actions happen when you call a state setter function?
-triggers react to re-render
-it keeps a cashe of state value
When does the local state variable get updated with the new value?
on the re-render
How do controlled components differ from uncontrolled components?
if it’s controlled, the parent
if it’s uncontrolled, … ?
What are some advantages of using uncontrolled components?
don’t have to use state,
it’s simpler!
What are some advantages of using controlled components?
it’s simpler to get the values out
Which style do you prefer?
“it’s really just a preference”
What two props must you pass to an input for it to be “controlled”?
value and …
on change?
What are some popular npm packages for creating forms in React?