React and JSX Flashcards

1
Q

What is JSX?

A

JSXis an XML-like syntax extension to ECMAScript w/o any defined semantics.

It is calledJSX, and it is a syntax extension to JavaScript.
Used to write HTML tags inside JavaScript.

JSXis an XML/HTML-like syntax used by React that extends ECMAScript so that XML/HTML-like text can co-exist with JavaScript/React code

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

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

A

JSX works with React.render() or createElement(); belongs to React

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

What is a React component?

A

Conceptually, components are like JavaScript functions.

Components let you split the UI into independent, reusable pieces.

Think about each piece in isolation.

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

How do you define a function component in React?

A
Function name (props) {
  Return (rendered React elements)
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you mount a component to the DOM?

A

By using ReactDOM.render

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 loader and install the babel-plugin that transforms React JSX

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

What are props in React?

A

They are objects; Props stand for properties; used to pass data between React components

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

How do you pass props to a component?

A

As an argument

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

How do you write JavaScript expressions in JSX?

A

Put them in brackets

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

How do you create “class” component in React?

A
keyword class name keyword extends react.component {
   render() {
      return the react elements
  }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you access props in a class component?

A

this.props

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

What is the purpose of state in React?

A

To keep track of values that will change over time

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

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

A

Pass the event handler to the react React element’s prop

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

What are controlled components?

A

A component who value is controlled by React

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

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

A

Value and onChange

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

WhatArraymethod is commonly used to create a list of React elements?

A

.map()

17
Q

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

A

.id

18
Q

When does React call a component’s componentDidMount method?

A

After render() the first time;

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

19
Q

Name three React.Component lifecycle methods.

A

componentDidMount, componentDidUpdate,

componentWillUnmount

20
Q

How do you pass data to a child component?

A

Props

21
Q

Describe React component lifecycle

A
// — mounting phase —
// constructor -> render -> componentDidMount -> …time passes … ->
// —updating phase —
// setState() or parent re-renders -> render (again!) -> componentDidUpdate