React Flashcards
What is React?
a javascript library for building user interfaces
helps you build fast and interactive UIs
it allows you to change data without reloading the page
allows you to build components and reuse them
What is a React element?
what gets returned from components
its an object that virtually describes the DOM nodes
that a component represents (or an object that describes an html element)
How do you mount a React element to the DOM?
by using ReactDOM.render() method
What is Babel?
a tool to convert ES2015+ code into a backwards compatible version of JS that can be run by older JS engines
What is a Plug-in?
a software component that adds on a specific feature to a program
when a program supports plugins, it enables customization
What is a Webpack loader?
they allow you to pre-process files as you import or “load” them
they can transform files from a different language (like TypeScript) to JavaScript
or load inline images as data URLs
or import CSS files directly from your JS modules
its recommended that you specify the them in your webpack.config.js file (by using module.rules)
or another way is inline which is specify them explicitly in each import statement
How can you make Babel and Webpack work together?
by installing babel-loader
What is JSX?
a syntax extension to JavaScript
when used in React, it describes what the UI should look like
it produces React “elements”
Why must the React object be imported when authoring JSX in a module?
because React must be in scope from your JSX code even though its not directly referenced
once we convert jsx into js, you’ll see that React.createElement is being used
How can you make Webpack and Babel work together to convert JSX into valid JavaScript?
by installing babel-loader and its plugin:
babel-loader
@babel/core
@babel/plugin-transform-react-jsx
What is a React component?
it lets you split the UI into independent, reusable pieces and think about each piece in isolation
components are like JS functions thats why we call components “Function Component”
they accept arbitrary inputs (called props) and return React elements describing what should appear on the screen
React component accepts a single “props” (stands for properties) object argument with data and returns a React element
How do you define a function component in React?
function keyword function name (HAS TO start with a capital letter or else the function gets passed as a string) props passed in () returns jsx
How do you mount a component to the DOM?
by calling the component function in between open and closed angle brackets
What are props in React?
props is a keyword in React that is used for passing data from one component to another
props is an object
you can pass any JS expression as a prop by surrounding it with { }
How do you pass props to a component?
in a (function) component, you can pass the props object into your function by specifying it in the () of the function component
to pass props, you want to assign value to props