React 19 breaks 'Rules of Hooks' with new use() API

Since 2018, the Golden Rule of React has been: "Never call Hooks inside loops, conditions, or nested functions." ⚛️ React 19 finally lets us break the "Rules of Hooks". This often forced us to read Context data at the top of a component, even if we were going to return null immediately after. It was inefficient and rigid. The new use() API changes this rule for Context. ❌ The Old Way (useContext): Must be called at the top level. If you try to put it inside an if (condition) block, React throws a hard error because the hook order changes between renders. ✅ The Modern Way (use): Can be called conditionally. You can now read Context only when you actually need it—inside if statements, loops, or after early returns. Why this is safe: use() is not technically a Hook (it doesn't rely on the linked-list order in the same way useState does), so it bypasses the restriction. Real-world Use Case: Performance optimization. If you have a heavy Context provider, you can now skip reading it entirely if a component early-returns. #ReactJS #React19 #WebDevelopment #Frontend #JavaScript #CleanCode #SoftwareEngineering #TechNews #ReactHooks #Hooks #FrontendDeveloper

  • text

Correction: This flexibility currently applies only to Context. You still cannot call useState or useEffect conditionally! Those still strictly follow the Rules of Hooks to maintain state persistence. 🧠

Just don't render your "Component" if the condition line 4 is true ? You don't need "use".

Important nuance here: React 19 did not remove the Rules of Hooks. useState, useEffect, useContext, etc still must be called at the top level in client components. The new use() API is not a hook and is mainly for Server Components to read async values or context during render. Calling hooks conditionally in client components is still invalid and will break. Mixing them is where confusion starts.

just throw away React. Problem solved!

React 19's update to the Rules of Hooks seems like a game-changer. I'm curious how this will impact performance in complex components.

See more comments

To view or add a comment, sign in

Explore content categories