React Flashcards
What is React?
a front end js framework
What is a React element?
an html element created by react
What is JSX?
Fundamentally, JSX just provides syntactic sugar for the React.createElement(component, props, …children) function. The JSX code:
Why must the React object be imported when authoring JSX in a module?
Since JSX compiles into calls to React.createElement, the React library must also always be in scope from your JSX code.
For example, both of the imports are necessary in this code, even though React and CustomButton are not directly referenced from JavaScript:
How can you make Webpack and Babel work together to convert JSX into valid JavaScript?
babel loader with jsx plugin
What is a React component?
class that returns a react element
How do you mount a component to the DOM?
ReactDOM.render()
What are props in React?
“Props” is a special keyword in React, which stands for properties and is being used for passing data from one component to another. Furthermore, props data is read-only, which means that data coming from the parent should not be changed by child components.
object argument with data
How do you pass props to a component?
When React sees an element representing a user-defined component, it passes JSX attributes and children to this component as a single object. We call this object “props”.
How do you write JavaScript expressions in JSX?
wrap it in curly braces
How do you create “class” component in React?
class keyword, name, render method
How do you access props in a class component?
this keyword
What Array method is commonly used to create a list of React elements?
map()
What is the best value to use as a “key” prop when rendering lists?
an id value from the data model
When does React call a component’s componentDidMount method?
componentDidMount() is invoked immediately after a component is mounted (inserted into the tree). Initialization that requires DOM nodes should go here. If you need to load data from a remote endpoint, this is a good place to instantiate the network request.