React.js Flashcards
What is React?
A JS library for building user interfaces
However, Tim believes it to be a framework moreso
What is a React element?
A plain object that virtually describes the DOM nodes that a component represents
How do you mount a React element to the DOM?
ReactDOM.render ( )
Or
ReactDOM.createRoot( )
Then root.render
What is JSX?
syntax extension to JS
produces React elements
Why must the React object be imported when authoring JSX in a module?
JSX will be creating a React object
under the hood it is actually React.createElement( )
How can you make Webpack and babel work together to convert JSX into valid JS?
babel loader
and
@babel/plugin-transform-react-jsx
What is a react component?
similar to a JS function
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?
function FunctionName (props) { return <h1>Hello, {props.name}</h1> }
How do you mount a component to the DOM?
React.render(, parent)
What are props in React?
arguments passed into React components that are objects
How do you pass props to a component?
propName=”propvalue”
How do you write JS expressions in JSX?
{expression}
has to be an expression
How do you create a “class” component in React?
class ComponentName extends React.Component { render ( ) { return <h1>Hello, {this.props.name}</h1>; } }
How do you access props in a class component?
using {this.props}
What is the purpose of state in React?
to keep track of values that change over time