Promises Flashcards

1
Q

What are the three states a Promise can be in?

A

pending, fulfilled, rejected

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

How do you handle the fulfillment of a Promise?

A

use the .then method and then you pass in an anonymous arrow functions

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

How do you handle the rejection of a Promise?

A

by calling the .catch( ) method, and take a function as its argument

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

What does fetch( ) return?

A

returns or fetches resources asynchronously across the network, init is optional which is an object containing any custom settings that you want to apply to the request
(returns a promise)

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

What is the default request method used by fetch( )?

A

GET is the default request method

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

How do you specify the request method (GET, POST etc.) when calling fetch?

A

add a second parameter with request method = init . ex: fetch(resource [, init])

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

When does React call component’s componentDidMount method?

A

invoked immediately after a component is mounted or inserted into the tree. If you need to load data from a remote endpoint, this a good place to instantiate the network request.(after first successful render)

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

Name three React.Component life cycle methods

A

mounting, updating, unmounting

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

How do you pass data to a child component?

A

by using this.state.(__) in the parent component then this.prop.data in the child component

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