React Flashcards
What is React?
a front-end JavaScript library for building interactive UIs
What is a React element?
an object which is a visible building block of a React app
How do you mount a React element to the DOM?
ReactDOM.render(elementToRender, container)
ex. ReactDOM.render(h1Element, document.getElementById(‘root’))
What is JSX?
a syntax extension to JavaScript which produces HTML-like React elements
Why must the React object be imported when authoring JSX in a module?
JSX compiles into calls to React.createElement()
How can you make Webpack and Babel work together to convert JSX into valid JavaScript?
install babel plugin-transform-react-jsx
What is a React component?
a function or class which returns React elements
How do you define a function component in React?
function keyword, capitalized name, (props), { return } ex. function Welcome(props) { return <h1>Hello, {props.name}</h1>;
How do you mount a component to the DOM?
ReactDOM.render(element, container)
library vs framework
library: you are in charge of the flow of the application, tell the library what to do (jQuery, React- concerned with rendering UI)
framework: framework is in charge of flow, it calls the code you plugged in as needed
(Bootstrap)
What are props in React?
an object, used to pass data into React components
How do you pass props to a component?
add props to element as a key/value pair
How do you write JavaScript expressions in JSX?
wrap in curly braces { expression }
How do you create “class” component in React?
‘class’ keyword + name, extends React.Component, render() { return Reactelement }
How do you access props in a class component?
this.props