Fetch Flashcards
What does fetch( ) return?
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.
What is the default request method used by fetch( )?
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 do you specify the request method (GET, POST, etc.) when calling fetch?
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”
}
When does React call a component’s componentDidMount method?
Right after the first time render( ) is called
Name three React.Component lifecycle methods.
constructor, render, componentDidMount
How do you pass data to a child component?
When you need to pass data from a parent to child class component, you do this by using props.