React Flashcards
What is React?
React is a JavaScript library for building user interfaces.
What is a React element?
A React element gets returned from React components, it is an object that virtually describes the DOM nodes a component represents.
How do you mount a React element to the DOM?
ReactDOM.render(element, target)
What is JSX?
JSX is an extension of JavaScript syntax used by React to allow for HTML-like text to exist in JavaScript code.
Why must the React object be imported when authoring JSX in a module?
Because React elements written in JSX are syntactic sugar for React.createElement calls.
How can you make Webpack and Babel work together to convert JSX into valid JavaScript?
Ensure that @babel/plugin-transform-react-jsx is listed as a Babel plugin in webpack.config.js
What is a React component?
React components are reusable pieces of code that accept a props argument and return React elements.
How do you define a function component in React?
function Comp(props) { return <h1>example</h1>; }
How do you mount a component to the DOM?
ReactDOM.render(reactElement, domTarget);
What are props in React?
Props are properties that get passed into React components and represent the properties of a React element.
How do you pass props to a component?
Specify them using key=”value” pairs in the opening tag of a React element representing a user-defined component.
How do you write JavaScript expressions in JSX?
Put them in curly braces.
How do you create “class” component in React?
class ComponentName extends React.Component { render() { return } }
How do you access props in a class component?
this.props
What is the purpose of state in React?
state is an object in a React component that keeps track of the state of a component and can be updated upon certain events.