File tree 1 file changed +13
-0
lines changed
src/app/hydration-stream-suspense
1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change 3
3
import { User } from "../types" ;
4
4
import { useQuery } from "@tanstack/react-query" ;
5
5
import Image from "next/image" ;
6
+ import React from "react" ;
6
7
7
8
async function getUsers ( ) {
8
9
return ( await fetch ( "https://jsonplaceholder.typicode.com/users" ) . then (
@@ -11,15 +12,27 @@ async function getUsers() {
11
12
}
12
13
13
14
export default function ListUsers ( ) {
15
+ const [ count , setCount ] = React . useState ( 0 ) ;
14
16
const { data, isLoading, isFetching, error } = useQuery < User [ ] > ( {
15
17
queryKey : [ "stream-hydrate-users" ] ,
16
18
queryFn : ( ) => getUsers ( ) ,
17
19
suspense : true ,
18
20
staleTime : 5 * 1000 ,
19
21
} ) ;
20
22
23
+ React . useEffect ( ( ) => {
24
+ const intervalId = setInterval ( ( ) => {
25
+ setCount ( ( prev ) => prev + 1 ) ;
26
+ } , 100 ) ;
27
+
28
+ return ( ) => {
29
+ clearInterval ( intervalId ) ;
30
+ } ;
31
+ } , [ ] ) ;
32
+
21
33
return (
22
34
< >
35
+ < p > { count } </ p >
23
36
{ error ? (
24
37
< p > Oh no, there was an error</ p >
25
38
) : isFetching || isLoading ? (
You can’t perform that action at this time.
0 commit comments