Fetch Flashcards

1
Q

What does fetch( ) return?

A

A Promise

The Fetch API provides a JavaScript interface for accessing and manipulating parts of the protocol, such as requests and responses. It also provides a global fetch( ) method that provides an easy, logical way to fetch resources asynchronously across the network.

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

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

A

Fetch takes two arguments, the “URL” and an object, “options”. Only the ‘URL’ is mandatory, and the method is set to GET by default if not provided.

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

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

A

You would pass an object as the second argument for fetch, and the method would be in that object

i.e.

fetch(url, {GET})

fetch(url, {
method: “GET”, // POST, PUT, DELETE, etc.
headers: {
// the content type header value is usually auto-set
// depending on the request body
“Content-Type”: “text/plain;charset=UTF-8”
}

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

When does React call a component’s componentDidMount method?

A

Right after the first time render( ) is called

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

Name three React.Component lifecycle methods.

A

constructor, render, componentDidMount

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

How do you pass data to a child component?

A

When you need to pass data from a parent to child class component, you do this by using props.

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