React Flashcards
What is React?
JavaScript library (framework) for building interfaces
What is a React element?
Object that describes a HTML element (DOM node)
How do you mount a React element to the DOM?
Call the render method of the root object then pass the react element into it
What is Babel?
A JavaScript compiler that converts new JavaScript terminology to old JavaScript terminology
What is a Plug-in?
Enhances a program’s capabilities
What is a Webpack loader?
Allows us to pre-processs files as we import or “load” them
How can you make Babel and Webpack work together?
- Install the proper devDependencies within the package.json
- Use the Babel loader
What is JSX?
A syntax extension of JavaScript that produces React “elements” and lets us write HTML-like syntax
Why must the React object be imported when authoring JSX in a module?
The React object has the methods needed to create the React elements
How can you make Webpack and Babel work together to convert JSX into valid JavaScript?
- Install
babel-loader
,@babel/core
, and the plugin@babel/plugin-transform-react-jsx
using NPM (don’t forgetwebpack
andbabel
in general) - Set the loader to run with the plugin in the
webpack.config.js
file - When Webpack starts bundling from
npm run build
, it will process.jsx
files using the plugin
What is a React component?
A function that outputs a React element
How do you define a function component in React?
- similar function style to JS
- Name of the function component must start with a capital
- Has one parameter
props
-
return
s a React element - Arguments are accessed with curly braces containing an expression, usually accessing the
props
object
How do you mount a component to the DOM?
- Query for the root DOM element
- Use
ReactDOM.createRoot()
method to create the React DOM root - Within that. use render() method with the desired React elements created from the React component inside
What are props in React?
Props is an object that is passed to a React component
How do you pass props to a component?
Pass ‘props’ to a component with key value pair attributes
Objects, variables, anything other than a string must be in curly braces