Conditional use() Calls: Breaking Hook Rules Intentionally
You'll learn why use() is the revolutionary exception that lets you conditionally call a Hook—something forbidden for all other Hooks.
The Rules of Hooks… Except for use()
For years, React has enforced strict Hook rules: always call Hooks at the top level, never conditionally, never in loops. This ensures consistent Hook order across renders. But use() deliberately breaks this rule.
Why the exception? Because use() reads values (Promises or Context) rather than creating stateful slots. It doesn't depend on call order like useState or useEffect do. This makes conditional calls safe.
Dynamic Data Fetching Based on Runtime Conditions
This unlocks powerful patterns:
function UserProfile({ userId, isGuest }) {
// Conditionally call use() based on authentication
if (isGuest) {
return <div>Please log in</div>;
}
// Only fetch data for authenticated users
const user = use(fetchUser(userId));
return <div>{user.name}</div>;
}
Or conditional data loading:
function Content({ shouldLoadComments, postId }) {
const post = use(fetchPost(postId));
// Conditionally read another Promise
if (shouldLoadComments) {
const comments = use(fetchComments(postId));
return <PostWithComments post={post} comments={comments} />;
}
return <PostOnly post={post} />;
}
The Analogy
Think of traditional Hooks like numbered lockers—you must visit them in the same order every time. But use() is like reading a letter someone hands you—you can choose whether to read it based on what's happening right now.
This enables runtime decisions about data dependencies without complex workarounds or wrapper components.
Key Takeaway: use() is intentionally designed to be called conditionally, enabling dynamic data fetching patterns that were impossible with traditional Hook rules—making it the first Hook that breaks the "no conditional calls" constraint.