Skip to content

Commit 7b68e06

Browse files
committed
App.JS unnecessary render reduced
1 parent 3a9260b commit 7b68e06

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

src/App.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,25 @@ class App extends Component {
1515
singleData: ''
1616
}
1717

18-
async getData() {
19-
const {data} = await axios('https://raw.githubusercontent.com/devsonket/devsonket.github.io/master/data/index.json');
20-
this.setState({data})
18+
getData() {
19+
const data = axios('https://raw.githubusercontent.com/devsonket/devsonket.github.io/master/data/index.json');
20+
return data;
2121
}
2222

23-
async topData() {
24-
const {data: tops} = await axios('https://raw.githubusercontent.com/devsonket/devsonket.github.io/master/data/top.json');
25-
this.setState({tops})
23+
topData() {
24+
const tops = axios('https://raw.githubusercontent.com/devsonket/devsonket.github.io/master/data/top.json');
25+
return tops;
26+
}
27+
28+
async getAllData() {
29+
const data = this.getData();
30+
const tops = this.topData();
31+
const getAllData = await Promise.all([data, tops]);
32+
this.setState({data: getAllData[0].data, tops: getAllData[1].data});
2633
}
2734

2835
componentDidMount() {
29-
this.getData();
30-
this.topData();
36+
this.getAllData();
3137
}
3238

3339
searchAItem = (term) => {
@@ -40,7 +46,7 @@ class App extends Component {
4046
render() {
4147
const { searchAItem } = this;
4248
const { tops, searchResult, data } = this.state;
43-
49+
4450
return (
4551
<BrowserRouter>
4652
<div className="App">

0 commit comments

Comments
 (0)