Slide 58
Slide 58 text
ASYNC(SERVER) STATE MANAGEMENT
S-W-R(STALE-WHILE-REVALIDATE) & REACT QUERY
• Most famous async state management library
• There are many features
• Caching
• Updating stale data when it stales (using
staleTime)
• Invalidate cache forcefully
• Provide loading state, error state to draw
screen more easily using those
function Example() {
const {data, isLoading, isError, refetch} =
useQuery(‘index’,
fetchData,
{ staleTime: 5000 }
);
if (isLoading) return Loading…
<
/
Text>
if (isError) return
<
/
View>
const invalidate = ()
=
>
{ queryClient.invalidateQueries(‘index’) }
return {data}Invalidate
<
/
View>
<
/
View>
}