Suppose I need to build a home page and I want the h1 and p to be rendered first and if the user scroll to the area of MyComponent, MyComponnet gets rendered or the async call in MyComponent does not prevent h1 or p rendering so that to have a better user experience. Is there a way I can do it?
const Home = () => {
return <div>
<h1>Home Page</h1>
<p>aaaaaaaaaa</p>
<p>aaaaaaaaaa</p>
<p>aaaaaaaaaa</p>
<MyComponent />
</div>;
}
const MyComponent = () => {
const res = await fetch('some url...');
// ... some code process the res
const data = processRes(res);
return <div>data</div>
}
React.suspenseto be finished which encapsulates the pattern for you in a "React aware" way.