React Flashcards
What is React?
JavaScript library for building user interfaces
What is a React element?
plain objects
How do you mount a React element to the DOM?
using ReactDOM.render(elementMade, root DOM node)
What is JSX?
a syntax extension to JavaScript that produces React “elements”
Why must the React object be imported when authoring JSX in a module?
the React library must always be in scope from your JSX code, since JSX compiles into calls to React.createElement
How can you make Webpack and Babel work together to convert JSX into valid JavaScript?
using babel loader with plugin @babel/plugin-transform-react-jsx
What is a React component?
similar to JavaScript functions, 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 Component (props) { return <h1>Hello, {props.name}</h1> ; }
How do you mount a component to the DOM?
use ReactDOM.render( react element created , root DOM node);
What are props in React?
properties used for passing data from one component to another
How do you pass props to a component?
as key value pairs, example text=’this’
How do you write JavaScript expressions in JSX?
wrap variables in curly braces
How do you create “class” component in React?
class Component extends React.Component { render( ) { return Example, {this.props.example} } }
How do you access props in a class component?
this.props
What is the purpose of state in React?
object that stores a component’s dynamic data and determines the component’s behavior
How do you pass an event handler to a React element?
provide a listener when the element is initially rendered onClick={eventHandlerMethod}