Tyler McGinnis Interview Questions Flashcards

1
Q

What happens when you call setState?

A

The first thing React will do when setState is called is merge the object you passed into setState into the current state of the component. This will kick off a process called reconciliation. The end goal of reconciliation is to, in the most efficient way possible, update the UI based on this new state. To do this, React will construct a new tree of React elements (which you can think of as an object representation of your UI). Once it has this tree, in order to figure out how the UI should change in response to the new state, React will diff this new tree against the previous element tree. By doing this, React will then know the exact changes which occurred, and by knowing exactly what changes occurred, will able to minimize its footprint on the UI by only making updates where absolutely necessary.

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

What’s the difference between an Element and a Component in React?

A

Simply put, a React element describes what you want to see on the screen. Not so simply put, a React element is an object representation of some UI.

A React component is a function or a class which optionally accepts input and returns a React element (typically via JSX which gets transpiled to a createElement invocation).

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

When would you use a Class Component over a Functional Component?

A

If your component has state or a lifecycle method(s), use a Class component. Otherwise, use a Functional component.

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

What is the Virtual DOM?

A

A JavaScript representation of the actual DOM.

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

What is React.Component?

A

The way to create a new component.

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

What is the render ( … method …) ?

A

Describes what the UI will look like for that component. Every component is required to have a render mkethod.

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

What does ReactDOM.render do?

A

Renders a React component to a DOM node.

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

What is ‘state’?

A

The internal data store (object) of a component.

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

What is ‘constructor (this.state)’?

A

The way in which you establish the initial state of a component.

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

What does ‘setState’ do?

A

This is a helper method used for updating the state of a

component and re-rendering the UI

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

What are ‘props’?

A

The data which is passed to the child component

from the parent component.

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

What are ‘propTypes’?

A

Allows you to control the presence, or types of

certain props passed to the child component.

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

What are ‘defaultProps’?

A

Allows you to set default props for your component.

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

What is the Component Lifecycle?

A
  • componentDidMount — Fired after the component is mounted
    • componentWillUnmount — Fired before the component will unmount
    • getDerivedStateFromProps - Fired when the component mounts and
      whenever the props change. Used to update the state of a component when its props change
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the component events?

A
  • onClick
    • onSubmit
    • onChange
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What happens after a user event in React?

A

Some user event which changes the state of your app → Re-render virtual DOM -> Diff previous virtual DOM with new virtual DOM -> Only update real DOM with necessary changes.

17
Q

What do we use to transform JSX to JS?

A

Webpack and Babel.

18
Q

What is JSX?

A

Allows us to write HTML like syntax which gets transformed

to lightweight JavaScript objects.

19
Q

What is ‘this.state’?

A

Any data you put on this.state inside of the constructor will be part of that component’s state.

20
Q

How does a component modify it’s own internal state?

A

We do this with a method called setState. ‘setState’ is a signal to notify our app some data has changed. Whenever setState is called, React creates a new virtual DOM, does the diff, then updates the real DOM.

21
Q

Describe componentDidMount

A

Invoked once after the initial render. Because the component has already been invoked when this method is invoked, you have access to the virtual DOM if you need it. You do that by calling this.getDOMNode(). So this is the lifecycle event where you’ll be making your AJAX requests to fetch some data.*

22
Q

Describe componentWillUnmout

A

This life cycle method is invoked immediately before a component is unmounted from the DOM. This is where you can do necessary clean up.

23
Q

Describe getDerivedStateFromProps

A

Sometimes you’ll need to update the state of your component based on the props that are being passed in. This is the lifecycle method in which you’d do that. It’ll be passed the props and the state, and the object you return will be merged with the current state.

24
Q

Describe the render() method

A

The Render method in a React component needs to be a pure function. That means it needs to be stateless, it needs to not make any Ajax requests, etc. It should just receive state and props and then render a UI.

25
Q

What are Lifecycle methods?

A

Lifecycle methods are special methods each component can have that allow us to hook into the views when specific conditions happen (i.e. when the component first renders or when the component gets updated with new data, etc).

26
Q

What did React Router v4 accomplish?

A

This version of React Router rewrote everything as just components.

27
Q

What do we need to do to make React Router work?

A
BrowserRouter allows React Router to pass the app’s routing information down to any child component it needs (via context). So to make React Router work, you’ll need to render BrowserRouter at the root of your application.Ex:
import {
  BrowserRouter as Router,
  Route,
  Link,
} from 'react-router-dom'