React Flashcards
What is React?
A JavaScript library for building user interfaces for building user interfaces based on UI components.
What is a React element?
an element in the dom
React elements are plain objects, desribes what you want the DOM to look like
A React element is an object representation of a DOM node or component instance building blocks
an object describing a component instance or DOM node and its desired properties
desribes what you want the DOM to look like
How do you mount a React element to the DOM?
with the render method of the reactdom object
ReactDOM.render(element, container[, callback])
How do you mount a React element to the DOM?
ReactDOM.render( )
method
What is Babel?
a JavaScript compiler
compiler takes one language to another
mainly used to convert ECMAScript 2015+ code into a backwards compatible version of JavaScript in current and older browsers or environments
What is a Plug-in?
a software component(branch of software) that adds a specific feature to an existing computer program
program would work without them
What is a Webpack loader?
are transformations that are applied to the source code of a module webpack does work without loader
They allow you to pre-process files as you import or “load” them A Webpack loader is a node module that applies transformations to the source code to of a module and outputs JavaScript
How can you make Babel and Webpack work together?
Install all dev dependencies
- webpack
- webpack-cli
- babel-loader
- @babel/core
- @babel/plugin-transformation-react-jsx
Configure webpack.config.js file to
- use babel loader as the loader
- use plugin transform react jsx
by adding babel-loader to the list of modules in webpack.config
How can you make Babel and Webpack work together?
Install all dev dependencies
- webpack
- webpack-cli
- babel-loader
- @babel/core
- @babel/plugin-transformation-react-jsx
Configure webpack.config.js file to
- use babel loader as the loader
- use plugin transform react jsx
by adding babel-loader to the list of modules in webpack.config as a loader
What is JSX?
A syntax extension of JavaScript.
which provides a way to structure component rendering using syntax familiar to many developers
generally used for react
supports JS and other stuff
Why must the React object be imported when authoring JSX in a module?
Becasue the React library must be in scope from the JSX code in order to make calls to React.createElement
So Babel understands to compile JSX to JS
How can you make Webpack and Babel work together to convert JSX into valid JavaScript?
by installing the react plugin
jsx plugin
- Specify in webpack.config.js to check for jsx to bundle
- Babel loader sends preprocessed files to babel core
- Plugin for convert JSX is read
- Converts to JS
babel loader
What is a React component?
components are like JavaScript functions. a JavaScript class or function that optionally accepts inputs i.e. properties(props) and returns a React element that describes how a section of the UI (User Interface) should appear.
How do you define a function component in React?
write a JavaScript function:
By writing a JavaScript function that accepts props as a single argument and returns a React element
How do you mount a component to the DOM?
render method of ReactDom
ReactDOM.render(element, container)
first argument of the render method
What are props in React?
They are objects used to pass data between react components
attribute like but are objects
How do you pass props to a component?
ComponentName (props) create element prop name = prop value Pass props in a function parameter Pass props into constructor function and define this.props in the constructor
How do you write JavaScript expressions in JSX?
{ and }
How do you create “class” component in React?
define a class that extends Component and has a render function define the render method has to return react element class and extends keyword
How do you access props in a class component?
the this property of the this object
implicit parameter
What is the purpose of state in React?
to represent an information about the component’s ‘current situation’
state object is where you store property values that belongs to the component
keep track of values that change over time
How to you pass an event handler to a React element?
With JSX you pass a function as the event handler, rather than a string.
as a prop
What Array method is commonly used to create a list of React elements?
Array.map( )
map
What is the best value to use as a “key” prop when rendering lists?
The best way to pick a key is to use a string that uniquely identifies a list item among its siblings. Most often you would use IDs from your data as keys:
What are controlled components?
components that maintain their own state
like inputform elements such as , , and typically maintain their own state and update it based on user input.
What two props must you pass to an input for it to be “controlled”?
onChange, value
When does React call a component’s componentDidMount method?
immediately after a component is mounted (inserted into the tree)
one time
constructor-render-componentdidmount
Name three React.Component lifecycle methods.
mounting, updating, unmounting
constructor, render, componentdidmount, componentdidupdate
How do you pass data to a child component?
By using the props object. Passing props is how info flows in React apps, from parents to children.