Suspense for data fetching

Suspense 미 사용 시 - waterfall

Promise.all로 해결 가능하지 않아?

Suspense 사용 시 - 희망편

// 이 함수는 Promise가 아니라 Suspense의 특별한 객체입니다.
const resource = fetchProfileData();

function ProfilePage() {
  return (
    <Suspense fallback={<h1>Loading profile...</h1>}>
      <ProfileDetails />
      <Suspense fallback={<h1>Loading posts...</h1>}>
        <ProfileTimeline />
      </Suspense>
    </Suspense>
  );
}

function ProfileDetails() {
  // Try to read user info, although it might not have loaded yet
  const user = resource.user.read(); //데이터를 읽는 메소드
  return <h1>{user.name}</h1>;
}

function ProfileTimeline() {
  // Try to read posts, although they might not have loaded yet
  const posts = resource.posts.read();
  return (
    <ul>
      {posts.map(post => (
        <li key={post.id}>{post.text}</li>
      ))}
    </ul>
  );
}

번외 : react-query의 onSuccess 안에서 setState를 사용해도 될까?