react Flashcards
What is React?
a JavaScript library for building user interfaces
What is a React element?
It’s an object that virtually describes the DOM nodes that a component represents
has key, props (children), ref, type(h1, div, etc), _owner
React element is a plain JS object that describes what the DOM obj should look like (NOT a DOM element)
framework stores in memory, not what we see?
How do you mount a React element to the DOM?
createElement
query DOM for real DOM element
createRoot using the DOM element
mount the createElement to DOM from root with render()
What is Babel?
toolchain used to convert JS versions (can convert code into older JS version syntax for browsers that might not support JS versions that are newer)
What is a Plug-in?
software component that adds a specific feature to an existing computer program.
adds more functionality or customization to a program
software already works w/o plug-in; plug-in is an add on
if some code of software modifies a larger piece of code/software that would’ve worked just fine w/o it, its a plugin
What is a Webpack loader?
transformations that are applied to the source code of a module. They allow you to pre-process files as you import or “load” them.
How can you make Babel and Webpack work together?
install bable core (babel)
install webpack
install babel-loader (connects the two above)
specify which babel plugins to use!!
What is JSX?
a syntax extension to JavaScript
JSX produces React “elements”
syntax extension used to write react elements
*extension: addon to JS
Why must the React object be imported when authoring JSX in a module?
b/c JSX is used to create React elements so you need react to do that
needs to be there so when JSX is converted to React.createElement, react is there
How can you make Webpack and Babel work together to convert JSX into valid JavaScript?
install bable/core, webpack, babel-loader
install @babel/plugin-transform-react-jsx plugin
user defined component
a function or a class
What is a React component?
basically a function or a class
independent and reusable bits of code. They serve the same purpose as JavaScript functions, but work in isolation and return HTML.
let you split the UI into independent, reusable pieces, and think about each piece in isolation.
How do you define a function component in React?
accepts a single “props” (which stands for properties) object argument with data and returns a React element
like JavaScript functions. They accept arbitrary inputs (called “props”) and return React elements describing what should appear on the screen.
function functionnamethatstartswithacapitalletter (optional props parameter) {
return a React element;
}
How do you mount a component to the DOM?
root.render()
create a react element w/ component name to put in render!!
**ex: root.render()
**don’t call function in render()
React is a framework, we define functions, classes, etc. but we don’t call functions in frameworks!!!
What are props in React?
an object!
looks like html attributes
kind of like parameters in JS functions?