React Flashcards
What is React?
A JavaScript library for creating user interfaces
What is a React element?
An object that describes what the DOM should look like
How do you mount a React element to the DOM?
ReactDOM.render
Keep in mind React takes over the whole DOM
What is JSX?
A syntax extension used in JavaScript, JSX produces React “elements”
Why must the React object be imported when authoring JSX in a module?
Because JSX will be called into React.createElement and therefore must be in scope
<h1></h1>
in React actually means -> React.createElement
How can you make Webpack and Babel work together to convert JSX into valid JavaScript?
Using babel-loader and the @babel/plugin-transform-react-jsx plugin
What is a React component?
Similar to JavaScript functions, they accept inputs called “props” and return React elements describing what should appear on the screen
How do you define a function component in React?
function FunctionName(props) { return elementChildrenContent, {props.name}; }
props is optional
How do you mount a component to the DOM?
ReactDOM.createRoot(document.getElementById(‘root’));
root.render(element);
What are props in React?
A JavaScript object
Children and attributes gathered into this object
How do you pass props to a component?
’ < componentName propName = propValue / >’
How do you write JavaScript expressions in JSX?
Surround it with curly braces
How do you create “class” component in React?
class ClassName extends React.Component { render( ) { return ' < React element type > ' React children { this.props.name } ' ' ; } }
How do you access props in a class component?
this
How does extends work?
Used in class declarations or expressions that creates a child class of another class