React Flashcards

1
Q

What is React?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a React element?

A

React elements are plain objects that describes what the dom looks like

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you mount a React element to the DOM?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Symbols

A

are special markers, usually are property keys or property values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Difference between library and framework

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is Babel?

A

It’s to ECMAScript 2015+ code into a backwards compatible version of JavaScript in current and older browsers or environments

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a Plug-in?

A

adds a specific feature to an existing computer program. When a program supports plug-ins, it enables customization

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a Webpack loader?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How can you make Babel and Webpack work together?

A

install the babel loader,

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is JSX?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Why must the React object be imported when authoring JSX in a module?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How can you make Webpack and Babel work together to convert JSX into valid JavaScript?

A

import the webpack and babel, with the react plugin, jsx transform plugin

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a React component?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you define a function component in React?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you mount a component to the DOM?

A

call the render method of the ReactDOM object with two arguments, what you want to mount and where you to append it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are props in React?

A

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

17
Q

How do you pass props to a component?

A

whatever the ComponentName (props)

18
Q

How do you write JavaScript expressions in JSX?

A

wrap it in { } curly braces

19
Q

How do you create “class” component in React?

A

you need to extend React.Component, inside the body, have the render subclass

20
Q

How do you access props in a class component?

A

Since we are using classes, we have to use this.props,

21
Q

What is the purpose of state in React?

A

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.

22
Q

How to you pass an event handler to a React element?

A

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.

23
Q

Virtual Dom

A

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

24
Q

What Array method is commonly used to create a list of React elements?

A

Map

25
Q

What is the best value to use as a “key” prop when rendering lists?

A

unique IDs, The best way to pick a key is to use a string that uniquely identifies a list item among its siblings. Most often you would use IDs from your data as keys:

it has to be unique

26
Q

What are controlled components?

A

a component that renders form elements and controls them by keeping the form data in the component’s state. In a controlled component, the form element’s data is handled by the React component (not DOM) and kept in the component’s state.

bound to react component state, this allows (forces) you to store the value in state and have a callback method.

27
Q

What two props must you pass to an input for it to be “controlled”?

A

handleChange, handleSubmit

28
Q

Name three React.Component lifecycle methods.

A

constructor()
render()
componentDidMount()
ComponentWillUpdate()

29
Q

When does React call a component’s componentDidMount method?

A

componentDidMount() is invoked immediately after a component is mounted (inserted into the tree).

after first successful render

30
Q

How do you pass data to a child component?

A

through the props

31
Q

four ways to trigger render() method:

A
  1. initial render
  2. setState()
  3. parent component re-render
  4. forceUpdate()