Dev.to WebDev 🛠 Dev 👁 0 📖 6 min read

`use()` Breaks the Rules of Hooks on Purpose. Here's the Catch.

You rip out a useEffect, a useState, and a cleanup flag, replace all three with one line of use(), and the component looks cleaner than it has in months. Then you refresh the page and the loading spinner never stops. Net

You rip out a useEffect, a useState, and a cleanup flag, replace all three with one line of use(), and the component looks cleaner than it has in months. Then you refresh the page and the loading spinner never stops. Network tab: the same request, firing again, and again, every few milliseconds, forever.

Nothing in the code is wrong, exactly. You just found the one rule use() actually enforces — by being the React API that's allowed to break every other rule.

The dance use() was built to end

Before use(), reading an async value inside a component meant writing the same fifteen lines everywhere:

function Profile({ userId }) {
  const [user, setUser] = useState(null);
  const [loading, setLoading] = useState(true);

  useEffect(() => {
    let cancelled = false;
    setLoading(true);
    fetchUser(userId).then((data) => {
      if (!cancelled) {
        setUser(data);
        setLoading(false);
      }
    });
    return () => { cancelled = true; };
  }, [userId]);

  if (loading) return <Spinner />;
  return <UserCard user={user} />;
}

Two pieces of state tracking one value. A cancelled flag so a slow response for the old userId doesn't overwrite a faster one for the new userId. None of it is about showing a user card — it's all plumbing to make useEffect behave like something it was never built to be: a way to read an async value.

use() reads it directly. No useEffect, no useState, no race-condition flag:

import { use, Suspense, useMemo } from "react";

function Profile({ userPromise }) {
  const user = use(userPromise);
  return <UserCard user={user} />;
}

function ProfilePage({ userId }) {
  const userPromise = useMemo(() => fetchUser(userId), [userId]);
  return (
    <Suspense fallback={<Spinner />}>
      <Profile userPromise={userPromise} />
    </Suspense>
  );
}

use(userPromise) either returns the resolved value or, if the promise is still pending, suspends — the same mechanism React.lazy uses. React walks up to the nearest <Suspense> and shows its fallback instead of rendering Profile with nothing. When the promise settles, React re-renders Profile, and use() just returns the value like it was there all along. One line replaced the whole dance, and the race-condition flag is gone because there's only one state to track: the promise.

Before you scroll — does anything in that second version look like it could go wrong? Sit with it for a second.

I simplified it one line further. That's when it broke.

The useMemo felt like an extra step, so I cut it:

// 🚫 looks identical, isn't
function Profile({ userId }) {
  const user = use(fetchUser(userId));
  return <UserCard user={user} />;
}

This is the version that floods the network tab. Here's why: every time Profile renders, fetchUser(userId) runs again and hands use() a brand-new promise object — even if userId hasn't changed. React has no way to know that this new promise represents "the same request, still loading." It only knows it was just handed a pending promise it's never seen before, so it suspends again. The fallback shows, the promise eventually resolves, Profile re-renders, and on that render it calls fetchUser(userId) one more time — producing yet another new, unseen, pending promise. The loop doesn't stop because nothing ever breaks the chain.

useMemo was never decoration. It was the one thing making the promise's identity stable across renders — the same promise object came back out every time, as long as userId stayed the same — so React could recognize "I've already seen this one, it's done, here's the value" instead of "new pending work, suspend again."

That's the actual rule use() enforces, and it's stricter than anything useEffect ever asked of you: the promise has to come from somewhere that caches it. That's usually one of three places — a parent component that memoizes it (like the useMemo above), a Server Component, where the promise can be created fresh each request because the request itself is the cache boundary, or a Suspense-integrated data library (React Query, SWR, Relay) that's already solving this for you. Creating a fresh promise inside the same component that calls use() on it, every render, is the one pattern that's never safe.

One thing worth knowing before you lean on the useMemo version in production: React's own docs skip useMemo for this and reach straight for a persistent cache (a module-level Map keyed by the request, so the same promise comes back no matter what re-renders) — because useMemo is documented as a performance optimization, not a guaranteed one. It works in the ProfilePage/Profile split above specifically because the memo lives in the parent, and the parent never suspends. Move that same useMemo down into the component that calls use(), and the first suspend throws the memoized value away with it — recreating the exact loop you were trying to fix.

🎮 Try it yourself

▶️ Open the interactive playground →

Runs right in your browser — poke at it and watch the concept react live.

Why it's an API, not a hook

Here's the part that's easy to miss if you only skim the React docs: use() doesn't sit on the "Hooks" page with useState and useEffect. It's listed separately, under React's general APIs — and that placement isn't an accident of alphabetizing.

Every other hook comes with the Rules of Hooks: call it unconditionally, at the top level, in the same order, every render. Break that rule with useState and React's internal bookkeeping desyncs — state attaches to the wrong slot. use() doesn't have that problem, because it isn't tied to a slot in the same way. You can call it inside an if, after an early return, or inside a loop:

function Message({ isLoggedIn, messagePromise }) {
  if (!isLoggedIn) {
    return <LoginPrompt />;
  }

  // Calling use() AFTER an early return is exactly what useState forbids.
  const message = use(messagePromise);
  return <p>{message}</p>;
}

A real hook here would be a lint error. use() is fine with it, because React re-evaluates each call to use() on its own, by reading from the thing you passed it, not from a fixed position in a call sequence. The same freedom applies to use(SomeContext) — unlike useContext, you can read it conditionally, which is genuinely useful for a component that only cares about a context value in one branch.

The freedom has a boundary, though: you can't wrap use() in your own try/catch. If the promise rejects, use() throws, and React expects an Error Boundary above it to catch that throw — the same contract as a render that throws for any other reason. If you want to handle the rejection yourself instead, attach .catch() to the promise before handing it to use(), so it never actually rejects on React's end.

The part worth keeping

use() isn't "useEffect but shorter." It's a different contract: you hand it something that eventually has a value, and it pauses the render until that value exists — but only if what you hand it stays recognizably the same thing across renders. Skip the caching and you get the one failure mode worse than the useEffect dance you were trying to delete: a spinner that looks broken but is actually working exactly as told, forever.

Where in your own code is a promise getting created fresh on every render because moving it up one level felt like overkill? That's the one to check first — before use() finds it for you in production.

🧠 Test yourself

Think it clicked? Take the 6-question quiz →

Instant feedback, a hint on every question, and an explanation for each answer — right or wrong.

📚 Read next

🚀 Want more like this? Every guide, playground, and quiz lives on bestpractic.org — open it and sign up free so the next one finds you.

Thanks for reading! Let's stay connected:

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.