Skip to content

Instantly share code, notes, and snippets.

@georgebyte
Created September 17, 2018 06:21
Show Gist options
  • Save georgebyte/b64528770dd1bfde37acfa11817848e4 to your computer and use it in GitHub Desktop.
Save georgebyte/b64528770dd1bfde37acfa11817848e4 to your computer and use it in GitHub Desktop.
Observable store fetch data "side effect"
loadData() {
this.setState({
...this.state,
requestInProgress: true,
});
return this.http.get(url).pipe(
tap(data => {
this.setState({
...this.state,
data: data,
requestInProgress: false,
});
}),
catchError(error => {
this.setState({
...this.state,
error: error,
requestInProgress: false,
});
return throwError(error);
})
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment