Migration Path: From useEffect Fetching to use()
You'll learn: How to refactor traditional useEffect data fetching patterns into the modern use() hook with Suspense.
The Old Pattern (useEffect Fetching)
For years, React developers have fetched data with useEffect: trigger a fetch on mount, manage loading/error states manually, and update state when data arrives. It works, but creates "waterfall" problems, requires boilerplate, and doesn't integrate with Suspense.
The New Pattern (use() + Suspense)
With use(), you move from imperative fetching (do this, then that) to declarative data consumption (here's a promise, React handles the rest). Instead of managing loading states yourself, you let Suspense catch the promise and show fallback UI automatically.
The Migration Process
Before (useEffect):
function UserProfile({ userId }) {
const [user, setUser] = useState(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
useEffect(() => {
fetchUser(userId)
.then(setUser)
.catch(setError)
.finally(() => setLoading(false));
}, [userId]);
if (loading) return <Spinner />;
if (error) return <Error message={error.message} />;
return <div>{user.name}</div>;
}
After (use()):
function UserProfile({ userId }) {
const user = use(fetchUser(userId));
return <div>{user.name}</div>;
}
// Wrap with Suspense + ErrorBoundary in parent
<ErrorBoundary fallback={<Error />}>
<Suspense fallback={<Spinner />}>
<UserProfile userId={123} />
</Suspense>
</ErrorBoundary>
The component becomes dramatically simpler. Loading and error states move to boundaries (Suspense and ErrorBoundary), not scattered throughout your component logic.
Key Takeaway: Migrating from useEffect fetching to use() means deleting manual state management and embracing Suspense boundaries for loading/error UI—your components focus purely on rendering data, not orchestrating fetch lifecycles.