React Flashcards

1
Q

What is React?

A

A JavaScript library for building user interfaces for building user interfaces based on UI components.

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

What is a React element?

A

an element in the dom
React elements are plain objects, desribes what you want the DOM to look like

A React element is an object representation of a DOM node or component instance building blocks
an object describing a component instance or DOM node and its desired properties
desribes what you want the DOM to look 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

with the render method of the reactdom object

ReactDOM.render(element, container[, callback])

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

How do you mount a React element to the DOM?

A

ReactDOM.render( )

method

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

What is Babel?

A

a JavaScript compiler
compiler takes one language to another
mainly used to convert 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
6
Q

What is a Plug-in?

A

a software component(branch of software) that adds a specific feature to an existing computer program
program would work without them

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

What is a Webpack loader?

A
are transformations that are applied to the source code of a module
webpack does work without loader
They allow you to pre-process files as you import or “load” them
A Webpack loader is a node module that applies transformations to the source code to of a module and outputs JavaScript
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How can you make Babel and Webpack work together?

A

Install all dev dependencies

  • webpack
  • webpack-cli
  • babel-loader
  • @babel/core
  • @babel/plugin-transformation-react-jsx

Configure webpack.config.js file to

  • use babel loader as the loader
  • use plugin transform react jsx

by adding babel-loader to the list of modules in webpack.config

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

How can you make Babel and Webpack work together?

A

Install all dev dependencies

  • webpack
  • webpack-cli
  • babel-loader
  • @babel/core
  • @babel/plugin-transformation-react-jsx

Configure webpack.config.js file to

  • use babel loader as the loader
  • use plugin transform react jsx

by adding babel-loader to the list of modules in webpack.config as a loader

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

What is JSX?

A

A syntax extension of JavaScript.
which provides a way to structure component rendering using syntax familiar to many developers
generally used for react
supports JS and other stuff

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

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

A

Becasue the React library must be in scope from the JSX code in order to make calls to React.createElement
So Babel understands to compile JSX to JS

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

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

A

by installing the react plugin
jsx plugin
- Specify in webpack.config.js to check for jsx to bundle
- Babel loader sends preprocessed files to babel core
- Plugin for convert JSX is read
- Converts to JS
babel loader

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

What is a React component?

A
components are like JavaScript functions.
a JavaScript class or function that optionally accepts inputs i.e. properties(props) and returns a React element that describes how a section of the UI (User Interface) should appear.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you define a function component in React?

A

write a JavaScript function:

By writing a JavaScript function that accepts props as a single argument and returns a React element

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

How do you mount a component to the DOM?

A

render method of ReactDom
ReactDOM.render(element, container)
first argument of the render method

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

What are props in React?

A

They are objects used to pass data between react components

attribute like but are objects

16
Q

How do you pass props to a component?

A
ComponentName (props)
create element
prop name = prop value 
Pass props in a function parameter
Pass props into constructor function and define this.props in the constructor
17
Q

How do you write JavaScript expressions in JSX?

A

{ and }

18
Q

How do you create “class” component in React?

A
define a class that extends Component and has a render function
define the render method 
has to return react element 
class and extends keyword
19
Q

How do you access props in a class component?

A

the this property of the this object

implicit parameter

20
Q

What is the purpose of state in React?

A

to represent an information about the component’s ‘current situation’
state object is where you store property values that belongs to the component
keep track of values that change over time

21
Q

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

A

With JSX you pass a function as the event handler, rather than a string.
as a prop

22
Q

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

A

Array.map( )

map

23
Q

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

A

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:

24
Q

What are controlled components?

A

components that maintain their own state

like inputform elements such as , , and typically maintain their own state and update it based on user input.

25
Q

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

A

onChange, value

26
Q

When does React call a component’s componentDidMount method?

A

immediately after a component is mounted (inserted into the tree)
one time
constructor-render-componentdidmount

27
Q

Name three React.Component lifecycle methods.

A

mounting, updating, unmounting

constructor, render, componentdidmount, componentdidupdate

28
Q

How do you pass data to a child component?

A

By using the props object. Passing props is how info flows in React apps, from parents to children.