React Flashcards

1
Q

What is React?

A

a JavaScript library that is used for building user interfaces specifically for single-page applications

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

What is a React element?

A

an object that gets returned from a React components and it describes what you want to see on the screen

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(reactElement, domContainerNode)

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

What is JSX?

A

a syntax extension to JavaScript to describe what the UI should look like

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

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

A

JSX is syntactic sugar for converting the “prettified” code into
React.createElement() and ReactDOM.render() methods after it’s compiled by Babel. Therefore, React & ReactDOM would need to be in scope

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

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

A

use Babel plug-in @babel/plugin-transform-react-jsx

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

What is a React component?

A
  • Components are like JavaScript functions that can take in “props” and return a React element to be rendered to the page.
  • Components let you split the UI into independent, reusable pieces, and think about each piece in isolation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you define a function component in React?

A

by writing a JavaScript function and returning a React element (named with a capital letter)

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

How do you mount a component to the DOM?

A
function Welcome() {
  return <h1>Hello</h1>;
}

ReactDOM.render(
;
document.getElementById(‘root’)
);

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

What are props in React?

A

Props are objects passed as arguments into React components

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

How do you pass props to a component?

A

erm

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

How do you write JavaScript expressions in JSX?

A

surround the JavaScript code in { } brackets

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

How do you create “class” component in React?

A

extend React.Component and add render() method

class Welcome extends React.Component {
  render() {
    return <h1>Hello, {this.props.name}</h1>;
  }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you access props in a class component?

A

using the “this” keyword

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

What is the purpose of state in React?

A

-to represent information about the component’s current situation

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

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

A

erm

  • event = {javascript expression}
  • properties
17
Q

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

A

map

18
Q

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

A
  • ideally, an ID from your data
  • if not available, use anything that would uniquely identify the item from its siblings (i.e. a name)
  • as a last resort, use item index
19
Q

What are controlled components?

A

a component that renders input form elements (input, textarea, select,…) and controls them by keeping the form data in the component’s state

20
Q

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

A

value={ }

onChange={ }