@@ -3,10 +3,23 @@ import useSWRList from 'swr/list'
3
3
import useSWR from 'swr'
4
4
import { useState } from 'react'
5
5
6
- const SWRListItem = ( { originKey, fetcher } ) => {
7
- const { data, error, isLoading, isValidating } = useSWR ( originKey , fetcher )
8
- console . log ( originKey , data , error , isLoading , isValidating )
9
- return < div > { data ? data : 'loading' } </ div >
6
+ const SWRListItem = ( { originKey, fetcher, listResult } ) => {
7
+ const { data, error, isLoading, isValidating, mutate } = useSWR (
8
+ originKey ,
9
+ fetcher
10
+ )
11
+ console . log (
12
+ originKey ,
13
+ data ,
14
+ error ,
15
+ isLoading ,
16
+ isValidating ,
17
+ listResult . data ,
18
+ listResult . error ,
19
+ listResult . isLoading ,
20
+ listResult . isValidating
21
+ )
22
+ return < div onClick = { ( ) => mutate ( ) } > { data ? data : 'loading' } </ div >
10
23
}
11
24
12
25
export default function Index ( ) {
@@ -15,7 +28,7 @@ export default function Index() {
15
28
'/api/data?id=1' ,
16
29
'/api/data?id=2'
17
30
] )
18
- const { data, result } = useSWRList ( keys , fetch , {
31
+ const { data, result, mutate } = useSWRList ( keys , fetch , {
19
32
SWRListItem,
20
33
keepPreviousData : true
21
34
} )
@@ -29,7 +42,7 @@ export default function Index() {
29
42
</ button >
30
43
< div > { result } </ div >
31
44
< h2 > -----***----</ h2 >
32
- < div >
45
+ < div onClick = { ( ) => mutate ( ) } >
33
46
{ data ? (
34
47
data . map ( v => < div key = { v . key } > { v . data ? v . data : v . error } </ div > )
35
48
) : (
0 commit comments