React Flashcards
What is React?
React is a declarative, efficient, and flexible JavaScript library for building user interfaces.
What is a React element?
plain objects that describe what you want to see on the screen.
How do you mount a React element to the DOM?
ReactDOM.render(element, container)
Using the ReactDOM.render( ) method:
ReactDOM.render(element, container[, callback])
ReactDOM.render( ) method takes a JSX expression, creates a corresponding tree of DOM nodes, and adds that tree to the DOM
What is JSX?
JSX is a syntax extension to JavaScript that produces React “elements”
A nice and readable way of creating elements in React
Why must the React object be imported when authoring JSX in a module?
You need to import react and react-dom in order to create DOM elements in React
How can you make Webpack and Babel work together to convert JSX into valid JavaScript?
Using a babel-loader along with a babel plugin to convert JSX
What is a React component?
Pieces of reusable code
Components are like JavaScript functions. They accept arbitrary inputs (called “props”) and return React elements describing what should appear on the screen.
independent and reusable bits of code.
They serve the same purpose as JavaScript functions, but work in isolation and return HTML.
How do you define a function component in React?
The simplest way to define a component is to write a JavaScript function.
You can also use an ES6 class to define a component.
By writing a JavaScript function that accepts props as a single argument and returns a React element
How do you mount a component to the DOM?
Using ReactDOM.render( ) method - use the function name as the type
What are props in React?
They are objects used to pass data between react components
How do you pass props to a component?
props as a parameter in your function/class
Add the prop to your JSX like you would add an attribute to an HTML tag
How do you write JavaScript expressions in JSX?
wrap it in { } curly braces
How do you create “class” component in React?
Begin with the class keyword followed by the className followed by extends React.Component and you must define the render( ) method.
How do you access props in a class component?
this
What is the purpose of state in React?
to contain data or information about the component. A component’s state can change over time; whenever it changes, the component re-renders
To store data that could be prone to change, and if it does change, trigger the render() method to update the DOM.
to control what you want the user to see on the webpage
To indicate a component’s current status*