1
- import { InfiniteScroll , List } from 'antd-mobile'
2
- import React , { useState } from 'react'
1
+ import { InfiniteScroll , List } from 'antd-mobile' ;
2
+ import React , { useState } from 'react' ;
3
+ import { history } from 'umi' ;
3
4
4
- let count = 0
5
+ let count = 0 ;
5
6
6
7
async function mockRequest ( ) {
8
+ console . log ( 'mockRequest' ) ;
7
9
if ( count >= 5 ) {
8
- return [ ]
10
+ return [ ] ;
9
11
}
10
- count ++
12
+ count ++ ;
11
13
return [
12
14
'A' ,
13
15
'B' ,
@@ -26,23 +28,23 @@ async function mockRequest() {
26
28
'O' ,
27
29
'P' ,
28
30
'Q' ,
29
- ]
31
+ ] ;
30
32
}
31
33
32
34
export default ( ) => {
33
- const [ data , setData ] = useState < string [ ] > ( [ ] )
34
- const [ hasMore , setHasMore ] = useState ( true )
35
+ const [ data , setData ] = useState < string [ ] > ( [ ] ) ;
36
+ const [ hasMore , setHasMore ] = useState ( true ) ;
35
37
async function loadMore ( ) {
36
- const append = await mockRequest ( )
37
- setData ( val => [ ...val , ...append ] )
38
- setHasMore ( append . length > 0 )
38
+ const append = await mockRequest ( ) ;
39
+ setData ( val => [ ...val , ...append ] ) ;
40
+ setHasMore ( append . length > 0 ) ;
39
41
}
40
42
41
43
return (
42
44
< >
43
45
< List >
44
46
{ data . map ( ( item , index ) => (
45
- < List . Item key = { index } > { item } </ List . Item >
47
+ < List . Item key = { index } onClick = { ( ) => history . goBack ( ) } > { item } </ List . Item >
46
48
) ) }
47
49
</ List >
48
50
< InfiniteScroll loadMore = { loadMore } hasMore = { hasMore } />
0 commit comments