React Flashcards
What is React?
React is a declarative, efficient, and flexible JavaScript library for building user interfaces
What is a React element?
React elements are plain objects that describe what you want to see on the screen.
How do you mount a React element to the DOM?
Using the ReactDOM.render( ) method:
ReactDOM.render(element, container[, callback])
ReactDOM.render( ) method takes a JSX expression, creates a corresponding tree of DOM nodes, and adds that tree to the DOM
What is JSX?
JSX is a syntax extension to JavaScript that produces React “elements”
Why must the React object be imported when authoring JSX in a module?
Because the React library must be in scope from your JSX code. It is not used explicitly but the compiler (Babel) uses it when converting JSX to React.createElement( )
How can you make Webpack and Babel work together to convert JSX into valid JavaScript?
By installing webpack, webpack-cli, babel-loader, @babel/core, @babel/plugin-transform-react-jsx to your packge.json devDependencies
What is a React component?
Components are like JavaScript functions. They accept arbitrary inputs (called “props”) and return React elements describing what should appear on the screen.
How do you define a function component in React?
The simplest way to define a component is to write a JavaScript function. You can also use an ES6 class to define a component.
How do you mount a component to the DOM?
Using ReactDOM.render( ) method - use the function name as the type
What is the difference between a library and a framework?
A library is code that you call (lodash is a library, you call it when you want it to return something.)
A framework is code that is called by the framework (You do not call your own components, React calls your components.
What are props in React?
JSX attributes and children as a single object
How do you pass props to a component?
Add the prop to your JSX like you would add an attribute to an HTML tag
How do you write JavaScript expressions in JSX?
You can put any valid JavaScript expression (not statements) inside curly braces in JSX
e.g: {2 + 2} , {user.firstName} , {formatName(user)} etc.
How do you create “class” component in React?
To define a React component class, you need to extend React.Component and you must define the render( ) method.
Begin with the class keyword followed by the className followed by extends React.Component
e.g: class CustomButton extends React.Component { render( ) { return {this.props.text}; } }
How do you access props in a class component?
Use this to access props in a class component.
e.g: this.props.propName