Course contentsShow
← React
Lesson 1000 of 2,39625. Custom HooksFree lesson

When Single-Component Logic Should Stay Inline

Identify scenarios where useState/useEffect complexity in one component doesn't warrant extraction despite seeming 'messy'.

When Single-Component Logic Should Stay Inline

What you'll learn: Sometimes the "mess" inside a single component is actually cleaner than extracting it into a custom hook.

The Core Idea

Just because a component has several useState and useEffect calls doesn't automatically mean you should extract them into a custom hook. If that logic is only used in one place and is tightly coupled to that specific component's needs, keeping it inline is often the right choice.

Think of it like organizing your kitchen. You wouldn't create a separate drawer labeled "Tuesday breakfast tools" just because your Tuesday morning routine involves a lot of steps. The tools stay in their normal places because the complexity is situational, not reusable.

When Inline Logic Wins

Component-specific state orchestration that doesn't repeat elsewhere should stay put. A form with three related fields, validation logic, and submission handling might look complex, but if it's unique to that form, extraction creates unnecessary indirection.

Context matters more than line count. A component with 10 lines of hook calls that are all specific to its UI concerns is clearer than splitting those into a custom hook with a confusing contract.

Reading locally is easier. When debugging, having the logic right there in the component—where you can see how state connects to JSX—beats jumping between files to understand a useSpecialFormLogic hook that's only used once.

The Real Question

Ask yourself: "Would another component ever need this exact combination of logic?" If no, and if the component itself remains readable, leave it alone. Extraction has a cost: abstraction overhead, naming challenges, and mental context-switching.

Key Takeaway: Not all complexity deserves extraction—single-use, component-specific hook logic often belongs inline where it's easiest to understand and maintain.