React Flashcards
What is React?
React makes it painless to create interactive UIs.
React will efficiently update and render just the right components when your data changes.
React is all about creating custom, reusable DOM elements and structuring the flow of data throughout the page, from actions taking place (example: user inputs text and pressed “return”) to the view being updated. It’s meant to provide a way to structure your interactions so that events that update the DOM flow through your components from highest in the DOM tree to lowest, updating the UI as changes happen that modify its state.
What is a React element?
React elements are plain objects that describes what the dom looks like
How do you mount a React element to the DOM?
through ReactDOM, Mounting” is when React “renders” the component for the first time and actually builds the initial DOM from those instructions.
ReactDom.render method
Symbols
are special markers, usually are property keys or property values.
Difference between library and framework
concept of inversion of control, Dom is a framework
Framework is a subset of a library that has inversion of control. give up control, it’s a framework
If you have control, it’s a library
What is Babel?
It’s to ECMAScript 2015+ code into a backwards compatible version of JavaScript in current and older browsers or environments
What is a Plug-in?
adds a specific feature to an existing computer program. When a program supports plug-ins, it enables customization
What is a Webpack loader?
Loaders are transformations that are applied to the source code of a module. pre-processing
Webpack by itself only knows javascript, so it needs additional help.
How can you make Babel and Webpack work together?
install the babel loader,
What is JSX?
JSX (JavaScript Syntax Extension and occasionally referred as JavaScript XML) is a React extension to the JavaScript language syntax[1]
which provides a way to structure component rendering using syntax familiar to many developers. It is similar in appearance to HTML.
Why must the React object be imported when authoring JSX in a module?
Becasue the React framework must be in scope from the JSX code in order to make calls to React.createElement
used in the final code that babel outputs
How can you make Webpack and Babel work together to convert JSX into valid JavaScript?
import the webpack and babel, with the react plugin, jsx transform plugin
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. either a class or function
How do you define a function component in React?
declare a function that you would ordinarly do. then have a return, have a HTML tag, then the content you want inside it. function gotta be uppercased
How do you mount a component to the DOM?
call the render method of the ReactDOM object with two arguments, what you want to mount and where you to append it
What are props in React?
stands for properties.
They are properties of a object used to pass data between react components. it’s what allows the re-usability,
uni-directional flow parent to child
treat them as read only
How do you pass props to a component?
whatever the ComponentName (props)
How do you write JavaScript expressions in JSX?
wrap it in { } curly braces
How do you create “class” component in React?
you need to extend React.Component, inside the body, have the render subclass
How do you access props in a class component?
Since we are using classes, we have to use this.props,
What is the purpose of state in React?
to represent an information about the component’s current situation.
Boils back to React dealing with interactiveness. When add a like to a instagram photo, the page doesn’t refresh, it adds 1. same with carts, with quantity, the price automatically updates.
The state gets replaced. the component gets re-rendered.
How to you pass an event handler to a React element?
you add an prop to whatever react element you’re returning, you distinguish what react event handler (make sure casing matters) through its attribute name, and its value determines what you want to do. make sure to have javascript expression, and call whatever function.
Virtual Dom
react elements describe what doom looks like, 2nd part react reconcialtion algo, how react tells the difference between the old react elements and the new one
What Array method is commonly used to create a list of React elements?
Map