React Flashcards

1
Q

What is React?

A

A JavaScript framework for building user interfaces

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

What is a React element?

A

A React Element is what gets returned from components. It’s an object that virtually describes the DOM nodes that a component represents.

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

ReactDOM.render(element, $container)

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

What is Babel?

A
  • JavaScript Compiler

- Converts ES2015+ code into backwards compatible javascript for older browsers or environments

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

What is a Plug-in?

A

A software component that adds a specific feature to an existing computer program

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

What is a Webpack loader?

A

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

What is JSX?

A

JSX is a syntax extension to JavaScript

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

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

A

So Babel understands to compile JSX to JS

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

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

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

What is a React component?

A

Components are like functions and classes, they accept props and return a React element

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

How do you define a function component in React?

A
  • Use JavaScript function syntax

function Example(prop) {}

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

How do you mount a component to the DOM?

A

ReactDOM.render(element, container)

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

What are props in React?

A

Props are an object of arguments passed into React components

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

How do you pass props to a function component ?

A

Pass props in a function parameter

Pass props into constructor function and define this.props in the constructor

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

How do you write JavaScript expressions in JSX?

A

Expression inside of curly brackets

{ 1 + 2 }

17
Q

How do you create “class” component in React?

A
  • class Example extends React.Component

- render method & return React element

18
Q

How do you access props in a class component?

A
  • Pass props in the constructor of a class

- this.props

19
Q

What is the purpose of state in React?

A

Data model that represents info about the current state

20
Q

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

A
  • React event handlers are passes as props
  • If function will be invoked by event, pass this.functionName inside curly brackets
  • Bind this is necessary if the function is not being manually invoked
21
Q

When does React call a component’s componentDidMount method?

A
  • After constructor

- After first render

22
Q

Name three React.Component lifecycle methods.

A
  • componentDidMount
  • componentDidUpdate
  • componentWillUnmount

*Render and constructor are also lifecycle methods

23
Q

How do you pass data to a child component?

A

Through props