Promises Flashcards
What are the three states a Promise can be in?
pending, fulfilled, rejected
How do you handle the fulfillment of a Promise?
use the .then method and then you pass in an anonymous arrow functions
How do you handle the rejection of a Promise?
by calling the .catch( ) method, and take a function as its argument
What does fetch( ) return?
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)
What is the default request method used by fetch( )?
GET is the default request method
How do you specify the request method (GET, POST etc.) when calling fetch?
add a second parameter with request method = init . ex: fetch(resource [, init])
When does React call component’s componentDidMount method?
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)
Name three React.Component life cycle methods
mounting, updating, unmounting
How do you pass data to a child component?
by using this.state.(__) in the parent component then this.prop.data in the child component