React Flashcards
What is React?
JavaScript library for creating user interfaces
What is a React element?
plain objects that contain information needed to turn it into a DOM
How do you mount a React element to the DOM?
Using ReactDOM.render(element, container [, callback])
What is JSX?
It is syntactic sugar for creating React elements
Why must the React object be imported when authoring JSX in a module?
It is just syntactic sugar for createElement method of the React object
How can you make Webpack and Babel work together to convert JSX into valid JavaScript?
Install both webpack and babel/babel-loader. Use babel plug-in for converting JSX
What is a React component?
Essentially just a function that returns a react element
How do you define a function component in React?
Normal function definition, but React components have first letter capitalized
Can also define a component via class: class ComponentFunction extends React.Component { render( ) { return <h1> Hello, {this.props.name}</h1>; } }
How do you mount a component to the DOM?
Using the ReactDOM.render( ) method
What are props in React?
Props are essentially objects that get passed into the createElement method that get attached to the React element in a way that mimics HTML attributes
How do you pass props to a component?
as property=value pairs within the JSX syntax
How do you write JavaScript expressions in JSX?
can embed JS expressions by enclosing them in squiggly brackets { }
How do you create “class” component in React?
class Component extends React.Component { render( ) { return reactElement; } }
How do you access props in a class component?
Through this.props
What is the purpose of state in React?
an object that is maintained within the component that indicate its current state