React Flashcards

1
Q

What is React?

A

a JS library for building user interfaces.

component based.

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 functions as a DOM element

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(element, container[,callback])

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

What is JSX?

A

js syntax extension

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

bc it gets transformed into react.create element

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

we need babel-loader and the 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

a reusable piece of React that describes a piece of the UI

any fxn that starts with CAPITAL LETTER
& returns JSX

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 Welcome(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

ReactDOM.render(element, mountingElement);

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

What are props in React?

A

how we pass data into a component.

they look like attributes

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

key value pair on jsx component that resembles an attribute

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

wrap them with curly brace

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
class className extends React.Component {
   render( ) {
   return (jsx)
   }
}

***RENDER METHOD IS REQUIRED!

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

this.props.propertyName

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

class CustomButton extends React.Component

What is Component?

A

Component

is a class that contains props and we are EXTENDING its functionality and thus inherit all the methods of parent class (like prototype almost).

This is how you can access this.props.propertyName in your custom class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
class CustomButton extends R.Component {
   constructor(props) {
     super(props)
     }
   }
A

super(props)

super calls parent’s constructor with SUPER and pass it the props

17
Q

What is the purpose of state in React?

A

manage changing data in component

18
Q

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

A
  1. use constructor to set initial state
  2. add method to change/set state upon event
  3. bind the method to constructor
  4. in component’s render ( ), set up ? : to render different results
19
Q

When does React call a component’s componentDidMount method?

A

immediately after component is mounted (inserted into tree)

OR

after render() method is called for the first time

20
Q

Name three React.Component lifecycle methods.

A

NEVER CALL THESE OURSELVES IN ANOTHER METHOD!

componentDidMount( ) - most commonly used for fetch requests

componentDidUpdate( ) - either props or state has changed (or both);

  • don’t need it too often; usually there’s a better way to do it
  • **do not call setState without an if stmt in this or INFINITE LOOP

componentWillUnmount( )

21
Q

How do you pass data to a child component?

A

through props