Week 10 - React Flashcards
What is a react component?
a function or class that returns a react element that represents a piece of your user interface
How do you define a function component in React?
Write a JS function with props as a parameter and the rendered react elements as a return
*name of the function needs to be capitalized
How do you mount a component to the DOM?
Render method of ReactDom
What are props in React?
props = properties
they are read-only objects used to pass data between react components
How do you pass props to a component?
pass them in as an argument with the prop name = value
How do you write JS expressions in JSX?
Surround it with curly braces
How do you create a “class” component in react?
Class keyword with component name (capitalized), extend React.Component, and define render() method which will return a react element
How do you access props in a class component?
this.props
What is the purpose of state in react?
Represents data/information about the component’s current status/situation
allows us to manage changing data in our app
How do you pass an event handler to a react element?
Pass it as a prop of the react element
What are controlled components?
an input form element whose value is controlled by React
What two props must you pass to an input for it to be “controlled”?
value and onChange
What array method is commonly used to create a list of react elements?
array.map
What is the best value to use as a “key” prop when rendering lists?
Ids from data as keys –> it’s a unique identifier
What does express.static() return?
a function