M3-React Flashcards
What is React?
A JavaScript library for building user interfaces
What is a React element?
It’s an object representing the DOM.
How do you mount a React element to the DOM?
react.render()
What is a React component?
It accepts arbitrary inputs (called “props”) and returns React elements describing a piece of UI.
How do you define a function component in React?
Example: function Welcome(props) { return <h1>Hello, {props.name}</h1>; } The first letter of the component name of the first letter should be capitalized. React treats components starting with lowercase letters as DOM tags.
How do you mount a component to the DOM?
ReactDOM.render()
Calling the render method of the ReactDOM object.
How can you make Webpack and Babel work together to convert JSX into valid JavaScript?
make sure there is a plugin -transform-react-jsx (answers need to be checked again)
Why must the React object be imported when authoring JSX in a module?
If you give some JSX to Babel, you will see that JSX is just sugar for React.createElement calls. This is why we need to import React if we use JSX.
What are props in React?
“Props” is a special keyword in React, which stands for properties and is being used for passing data from one component to another.
How do you pass props to a component?
Use attribute. key-value format.
How do you write JavaScript expressions in JSX?
You are to write the expressions surrounded by curly brackets.
How do you create “class” component in React?
Example from React Official Documentation:
class Welcome extends React.Component { render() { return <h1>Hello, {this.props.name}</h1>; } }
How do you access props in a class component?
Use ‘this’ keyword. => this.props.name
What is the purpose of state in React?
controls what’s display on the page.
How do you pass an event handler to a React element?
???