Suspense in React Native
Suspense is a feature of React that allows you to gracefully handle loading data by suspending rendering until all the parts of your components are ready to display. This can be useful for improving the user experience of your application by preventing them from seeing blank screens or errors while data is loading.
import React, { Suspense } from “react”;
<Suspense
fallback={
<ActivityIndicator size=”large” color=”#00ff00" />
}>
<FastImage
style={{
width: 58,
height: 58,
marginLeft: 12,
borderRadius: 2,
backgroundColor: ‘#D7FBCB’,
}}
source={{
uri: item.image_url,
priority: FastImage.priority.normal,
}}
resizeMode={FastImage.resizeMode.contain}
/>
</Suspense>
In this example, the Image
component is wrapped in a Suspense
component with a fallback of an ActivityIndicator
component. This means that if the Image
component is not ready to render, the ActivityIndicator
component will be rendered instead.