React Flashcards
What is React?
A JavaScript library for building user interfaces.
What is a React Element?
An Object
How do you mount a React element to the DOM?
reactDom.render(Element, Container[, callback])
What is JSX?
A syntax extension to JavaScript.
Why must the React object be imported when authoring JSX in a module?
Because JSX compiles into calls to React.createElement, the React library must also be in scope from the JSX code.
How can you make Webpack and Babel work together to convert JSX into valid JavaScript?
install the babel-loader as a devDependency.
add the plugin @babel/plugin-transform-react-jsx in the
What is a React component?
It is a “function” or “class” that accepts arbitrary inputs (called props) and return React elements describing what should appear on the screen.
How do you define a function component in React?
function keyword
Name (must start with capitalized letter)
(props)
return JSX
How do you mount a component to the DOM?
Assign the return of the component to a variable.
Call the render method of the ReactDom object
Pass the variable containing the component as the first argument in the render method then query the DOM for the element you are mounting the component to.
What are props in React?
Props is an object
When react sees an element representing a user defined component, it passes JSX attributes and children to this component as a single object.
How do you pass props to a component?
Pass it as an argument when the component is created?
How do you write JavaScript expressions in JSX?
Surround it with curly braces.
How do you create a “class” component in React?
class keyword followed by the name of the component followed by extends. Then call the Component method of the React object followed by curly braces. Define the render() method followed by opening curling braces and return the JSX.
There are other options we haven’t gone over yet.
How do you access props in a class component?
this.props
What is the purpose of state in React?
To store property values that belong to components. When the state changes the component re-renders.