React.js Flashcards

1
Q

What is React?

A

A JS library for building user interfaces

However, Tim believes it to be a framework moreso

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

What is a React element?

A

A plain 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 ( )

Or

ReactDOM.createRoot( )
Then root.render

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

What is JSX?

A

syntax extension to JS

produces React elements

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 will be creating a React object

under the hood it is actually React.createElement( )

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 JS?

A

babel loader

and

@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

similar to a JS function

They accept arbitrary inputs (called props) and return React elements describing what should appear on the screen

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
function FunctionName (props) {
      return  <h1>Hello, {props.name}</h1>
}
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

React.render(, parent)

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

What are props in React?

A

arguments passed into React components that are objects

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

propName=”propvalue”

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

How do you write JS expressions in JSX?

A

{expression}

has to be an expression

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

How do you create a “class” component in React?

A
class ComponentName 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 {this.props}

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 keep track of values that change over time

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

onEvent={this.eventMethod}

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 a “key” prop when rendering lists?

A

a unique id that is stable and specific amongst its siblings

19
Q

What are controlled components?

A

those in which form data is handled by the component’s state.

20
Q

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

A

value=”valueOfSomething”

onchange=”value”

21
Q

When does React call a component’s componentDidMount method?

A

immediately invoked after a component is mounted (inserted into the tree).

22
Q

Name three React.Component lifecycle methods:

A

componentDidMount()

componentDidUpdate()

componentWillUnmount()

render()

23
Q

How do you pass data to a child component?

A

pass a “prop”