React Flashcards

1
Q

What is React?

A

JavaScript library (framework) for building interfaces

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

What is a React element?

A

Object that describes a HTML element (DOM node)

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

Call the render method of the root object then pass the react element into it

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

What is Babel?

A

A JavaScript compiler that converts new JavaScript terminology to old JavaScript terminology

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

What is a Plug-in?

A

Enhances a program’s capabilities

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

What is a Webpack loader?

A

Allows us to pre-processs files as we import or “load” them

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 the proper devDependencies within the package.json
  • Use the Babel loader
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is JSX?

A

A syntax extension of JavaScript that produces React “elements” and lets us write HTML-like syntax

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

The React object has the methods needed to create the React elements

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
  • Install babel-loader, @babel/core, and the plugin @babel/plugin-transform-react-jsx using NPM (don’t forget webpack and babel in general)
  • Set the loader to run with the plugin in the webpack.config.js file
  • When Webpack starts bundling from npm run build, it will process .jsx files using the plugin
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a React component?

A

A function that outputs 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
  • similar function style to JS
  • Name of the function component must start with a capital
  • Has one parameter props
  • returns a React element
  • Arguments are accessed with curly braces containing an expression, usually accessing the props object
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
  • Query for the root DOM element
  • Use ReactDOM.createRoot() method to create the React DOM root
  • Within that. use render() method with the desired React elements created from the React component inside
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are props in React?

A

Props is an object that is passed to a React component

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

How do you pass props to a component?

A

Pass ‘props’ to a component with key value pair attributes

Objects, variables, anything other than a string must be in curly braces

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

Wrap them in curly braces, otherwise they’re the same as JavaScript expressions

17
Q

How do you create “class” component in React?

A

class (name starting with capital letter), extends React.component and code block with render method inside it

18
Q

How do you access props in a class component?

A

this.props

19
Q

What is the purpose of state in React?

A

State allows a React element to not only handle events but also keep the functionality of handling events within the component

20
Q

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

A

Within the return of the React element (the render()), add the event as a prop to the React element and specify the handler function as the value to that prop but remember to enclose it within curly braces and specify that it is a method of this

21
Q

What are controlled components?

A

Form element controlled by react

They render the form control and the state of the form control

22
Q

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

A
  • value that holds the associated key value in curly braces {this.state}
  • onChange event handler that uses setState()
23
Q

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

A

the map method

24
Q

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

A

An ideal key would be one that uniquely identifies a list item from its siblings, from the source data

25
Q

What does React call a component’s ‘componentDidMount’ method?

A

After the first successful render is called for the first time

26
Q

Name 3 React.Component lifecycle methods.

A
  • componentDidMount()
  • componentDidUpdate()
  • componentWillUnmount()
  • render()
27
Q

How do you pass data to a child component?

A

The parent can hold the data in its state, and pass that data as a prop to the child component when creating the child element

In short, via PROPS