React Flashcards
What is React?
React is a free and open-source front-end JavaScript library for building user interfaces based on UI components.
What is a React element?
A React Element is what gets returned from components. It’s an object that virtually describes the DOM nodes that a component represents. With a function component, this element is the object that the function returns. With a class component, the element is the object that the component’s render function returns.
How do you mount a React element to the DOM?
ReactDOM.render( )
what is JSX?
Its a syntax extension to JavaScript.
JSX stands for JavaScript XML. JSX allows us to write HTML in React.
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.
How can you make Webpack and Babel work together to convert JSX into valid JavaScript?
babel-loader?
What is a React component?
Components are independent and reusable bits of code. They serve the same purpose as JavaScript functions, but work in isolation and return HTML. Components come in two types, Class components and Function components, in this tutorial we will concentrate on Function components.
function or class and returns a react element. it can be an element tree.
How do you define a function component in React?
So a Functional Component in React: is a JavaScript/ES6 function. must return a React element (JSX) always starts with a capital letter (naming convention) takes props as a parameter if necessary.
How do you mount a component to the DOM?
ReactDOM.render( react-element, container)
What are props in React?
React has a special object called a prop (stands for property) which we use to transport data from one component to another.
How do you pass props to a component?
To the component as an argument
How do you write JavaScript expressions in JSX?
To write a JavaScript expression within JSX you will have to surround the JavaScript code in { } brackets. In the React/JSX code below I am mixing JavaScript expressions (e.g., 2+2 ), surround by { } among the JSX that will eventually get evaluated by JavaScript.
How do you create “class” component in React?
Creating a class component is pretty simple; just define a class that extends Component and has a render function.
render() purpose is to return the react element. thats it.
How do you access props in a class component?
using ‘this’ keyword
What is the purpose of state in React?
State is a plain JavaScript object used by React to represent an information about the component’s current situation. It’s managed in the component (just like any variable declared in a function)
keep track of values which change over time