React Flashcards

1
Q

What is a Webpack?

A

Module bundler (that bundles JavaScript files for usage in a browser)

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

How do you add a devDependenccy to a package?

A

npm install -D packagename

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

What is an NPM script?

A

A way to bundle common shell commands for a project

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

How do you execute Webpack with npm run?

A

npm run build

“build” is written in the “scripts” of the package.json file - it can be named something else too

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

How are ES modules different from CommonJS modules?

A

o ES modules import everything before the code is executed unlike CommonJS modules which load dependencies on demand while the code is getting executed

o Different syntax (CommonJS uses require and ES uses import)

o ES module syntax is part of the language but CommonJS modules need a loader (it’s not an official standard- instead it’s a community library)

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

What kind of modules can Webpack support?

A

o ECMAScript modules
o CommonJS modules
o AMD modules
o Web Assembly

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

What is React?

A

A JavaScript library for building UI

Actually a framework

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

What is a React element?

A

Plain object that describes what a DOM should look like

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

What is Babel?

A

JavaScript compiler used to convert latest ECMAScript code into a backwards compatible version of JS

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

What is a Webpack loader?

A

Tool that pre-processes a file before importing with plug-ins

(Tool that helps webpacks interpret and translate files in order to bundle static assets)

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

How can you make Babel and Webpack work together?

A

npm install babel-loader as a devDependency

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

What is JSX?

A

o JavaScript XML

o Syntax extension to JavaScript

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

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

A

Because it’s used in the final code of babel outputs (babel calls React.createElement in its output so ‘createElement’ would not work without the ‘React’ object)

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

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

A
  1. npm install @babel/plugin-transform-react-jsx

2. npm install babel-loader

17
Q

What is a React component?

A

Function or a class that generates React elements

18
Q

How do you define a function component in React?

A

By writing a JavaScript function (and the function name MUST start with a capital letter)

19
Q

How do you mount a component to the DOM?

A

ReactDOM.render(ReactElementName, container)

20
Q

What are props in React?

A

o Arguments passed into React components

o Properties of an object

21
Q

How do you pass props to a component?

A

By giving it key:value pairs

22
Q

How do you write JavaScript expressions in JSX?

A

By surrounding it with curly braces

23
Q

How do you create “class” component in React?

A
class  extends React.Component {
    render () {
  }
}
24
Q

How do you access props in a class component?

A

this.prop.keyName

25
Q

What is the purpose of state in React?

A

To indicate a component’s current status

26
Q

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

A

As props to child components

27
Q

What are controlled components?

A

An input form element whose value is controlled by React

28
Q

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

A
  • onChange

- value

29
Q

When does React call a component’s componentDidMount method?

A

After the first successful render

30
Q

Name three React.Component lifecycle methods.

A

o componentDidMount
o componentDidUpdate
o componentWillUnmount

and
o shouldComponentUpdate

31
Q

How do you pass data to a child component?

A

Using props