React.js Flashcards
What is React?
A JavaScript library for building user interfaces.
What is a React element?
An object; An element describes what you want to see on screen. Unlike a DOM element, React elements are plain objects, and are cheap to create.
How do you mount a React element to the DOM?
With the render method of the ReactDOM object;
ReactDOM.render(element, container[, callback]
What is JSX?
A syntax extension for JavaScript used with react to describe what the UI should look like.
Why must the React object be imported when authoring JSX in a module?
Because JSX produces React “elements”.
How can you make Webpack and Babel work together to convert JSX into valid JavaScript?
By adding the @babel/plugin-transform-react-jsx, babel-loader too.
What is a React component?
A React component is conceptually like a JavaScript function. They accept arbitrary inputs called (“props”) and return React elements describing what should appear on screen.
How do you define a function component in React?
You can write a JavaScript function accepting “props” as a single object parameter and returning a React element;
You can also use ES6 classes.
How do you mount a component to the DOM?
With the render method of the ReactDOM object.
(first argument is a react element, using the function name as the type. Second is where you would like it to be mounted.)
What are props in React?
props are single object arguments which contain the properties of a react element.
How do you pass props to a component?
By passing the props object as a parameter in the component definition, and then accessing it via JavaScript Expressions; ( within the react Element )
How do you write JavaScript expressions in JSX?
By enclosing the JavaScript expression in curly braces. Then you can add in whatever expression you want, (besides if/or)
How do you create “class” component in React?
class ‘ComponentName’ extends React.Component {
render ( ) {
return ‘reactElement’
({this.props.text})
How do you access props in a class component?
with ‘this.props’
What is the purpose of state in React?
So we can change how an element renders over time. (vs having to create another element each time?)