React.js Flashcards
What is React?
React is a JavaScript library for building user interfaces.
What is a React element?
A React Element is what gets returned from components.
It’s an object that virtually describes the DOM nodes that a component represents.
An element is a plain object describing a component instance or DOM node and its desired properties.
How do you mount a React element to the DOM?
By using ReactDOM.render
What is JSX?
JSX is an XML-like syntax extension to ECMAScript w/o any defined semantics.
It is called JSX, and it is a syntax extension to JavaScript.
Used to write HTML tags inside JavaScript.
JSX is an XML/HTML-like syntax used by React that extends ECMAScript so that XML/HTML-like text can co-exist with JavaScript/React code
Why must the React object be imported when authoring JSX in a module?
JSX works with React.render() or createElement(); belongs to React
How can you make Webpack and Babel work together to convert JSX into valid JavaScript?
Use babel loader and install the babel-plugin that transforms React JSX
What is a React component?
Conceptually, components are like JavaScript functions.
Components let you split the UI into independent, reusable pieces.
Think about each piece in isolation.
How do you define a function component in React?
Function Name (props) { return (rendered React elements) }
How do you mount a component to the DOM?
By using ReactDOM.render on the react element
What are props in React?
They are objects; Props stand for properties; used to pass data between React components
How do you pass props to a component?
’ ‘ if it’s a string and { } if not.
How do you write JavaScript expressions in JSX?
put them in curly braces
How do you create “class” component in React?
keyword class name keyword extends react.component { render() { return the react elements } }
How do you access props in a class component?
this.props
What is the purpose of state in React?
To keep track of values that will change over time
How to you pass an event handler to a React element?
Pass the event handler to the React element’s prop // pass in a function as an event handler
What are controlled components?
a component whose input’s value is always driven by the React state. you can now pass the value to other UI elements too, or reset it from other event handlers.
What two props must you pass to an input for it to be “controlled”?
Value and onChange
What Array method is commonly used to create a list of React elements?
.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:
When does React call a component’s componentDidMount method?
immediately after a component is mounted (inserted into the tree).
Name three React.Component lifecycle methods.
constructor, render, componentDidMount, didunmount, update, error handling
How do you pass data to a child component?
through props. (passing a prop as a javascript expression