File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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" >
You can’t perform that action at this time.
0 commit comments