React Flashcards
What is React?
A JavaScript library for building user interfaces
A library is a JavaScript file that contains a bunch of functions, and those functions accomplish some useful task for your webpage.
What is a React element?
An element describes what you want to see on the screen:
How do you mount a React element to the DOM?
ReactDOM.render(element, container[, callback])
Unlike browser DOM elements, React elements are plain objects, and are cheap to create. React DOM takes care of updating the DOM to match the React elements.
What is JSX?
A syntax extension to JavaScript, it produces react elements and lets you use HTML syntax in JavaScrupt
Why must the React object be imported when authoring JSX in a module?
The JS will be undefined if you don’t
How can you make Webpack and Babel work together to convert JSX into valid JavaScript?
Add this to webpack config file, loader: 'babel-loader', options: { plugins: [ '@babel/plugin-transform-react-jsx' ]
What is a React component?
Components let you split the UI into independent, reusable pieces, and think about each piece in isolation.
How do you define a function component in React?
function CustomButton([props]) { return Click Me!; };
How do you mount a component to the DOM?
ReactDOM.render(
,
document.querySelector(‘#root’)
);
What are props in react
objects getting passed to react elements
How do you pass props to a component?
like arguments
const element = ( <div>
</div>
);
How do you write JavaScript expressions in JSX?
close expression in curly braces, they mean stark end of a JavaScript expression
How do you create “class” component in React?
class CustomButton extends React.Component { render() { return {this.props.text}; } }
A render method is required
How do you access props in a class component?
{this.props.text}
What is the purpose of state in React?
React components has a built-in state object. The state object is where you store property values that belongs to the component. When the state object changes, the component re-renders.
State is like our data model for React, we use it to determine what the user should see when it renders.