From d86a1c27e2c35b1ac91ab760901909379b80eb7e Mon Sep 17 00:00:00 2001
From: Artem Veremienko <temaspsxxx@gmail.com>
Date: Tue, 29 Dec 2020 00:34:43 +0200
Subject: [PATCH] Add throttling
---
src/App.js | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/App.js b/src/App.js
index 21d056f..799f215 100644
--- a/src/App.js
+++ b/src/App.js
@@ -29,6 +29,8 @@ class App extends Component {
class News extends Component {
_isMounted = false;
+ // throttle time
+ ms = 2000;
constructor(props) {
super(props);
@@ -43,6 +45,7 @@ class News extends Component {
axios
.get('https://hn.algolia.com/api/v1/search?query=react')
+ .then(response => new Promise(res => setTimeout(() => res(response), this.ms)))
.then(result => {
if (this._isMounted) {
this.setState({