Skip to main content

7 React Patterns That Made Me Code Smarter, Not Harder

 


It’s 4 AM. I’m knee-deep in spaghetti code. My useEffect dependencies are screaming, the UI flickers like a cheap horror movie, and some mystery re-render is haunting my app every time I breathe.

Classic React chaos. Ever been there?

I was a decent developer. But React humbled me. Hard.

Turns out, knowing useState And slapping on some JSX doesn’t mean you know what the hell you’re doing. It means you started. But to ship maintainable, scalable apps? You need patterns. Real ones.

Here are 7 React patterns that slapped sense into me — and might just save your sanity too.


Edited by me

1. The “Component as Function, Not Dumpster” Pattern

You know what I’m talking about.

That one component that does everything. Fetches data, renders UI, handles logic, scrolls the page, makes your coffee…

Stop. Please.

A component should do one thing well, not ten things poorly.

The Fix: Extract. Abstract. Repeat.

// Bad
function UserProfile() {
const [data, setData] = useState(null);
useEffect(() => {
fetchUser().then(setData);
}, []);
return <div>{data?.name}</div>;
}

// Better
function useUser() {
const [data, setData] = useState(null);
useEffect(() => {
fetchUser().then(setData);
}, []);
return data;
}
function UserProfile() {
const user = useUser();
return <div>{user?.name}</div>;
}

Separation of concerns. It’s not just for backend nerds.

2. The “Hooks Are Just Functions” Realization

Remember when you first saw useEffectYou thought, "Wow, this is elegant."

Then you added three useEffects, two useStates, and now it’s bug soup.

Let’s be clear:

Hooks are just functions. You can write your own. And you should.

Custom hooks are the cheat code of React.

function useWindowWidth() {
const [width, setWidth] = useState(window.innerWidth);
useEffect(() => {
const handleResize = () => setWidth(window.innerWidth);
window.addEventListener('resize', handleResize);
return () => window.removeEventListener('resize', handleResize);
}, []);
return width;
}

Boom. Reusable. Clean. Understandable.

If you’re not writing custom hooks, you’re leaving Legos all over the floor.

3. The “Lift State, But Don’t Launch It Into Orbit” Principle

Yes, we’ve all heard it:

“Lift state up!”

Cool. But there’s a line.

If your parent component starts looking like a NASA control center, you’ve lifted too hard.

Keep the state close to where it’s needed. Only lift when necessary.

You don’t need a global state to control a dropdown. I promise.

4. The “Composition Over Configuration” Gospel

Tired of prop drilling like you’re digging for oil? Welcome to the club.

React’s secret sauce is composition. Use it.

function Modal({ children }) {
return <div className="modal">{children}</div>;
}
<Modal>
<h2>Are you sure?</h2>
<button>Yes</button>
<button>No</button>
</Modal>

Clean. Flexible. No props gymnastics.

Your component should be a LEGO brick, not a LEGO Death Star.

5. The “Render Props Aren’t Dead” Hot Take

Everyone acts like render props died when hooks came around.

They didn’t. They’re just chilling in a corner, waiting for someone to remember how powerful they are.

function MouseTracker({ render }) {
const [pos, setPos] = useState({ x: 0, y: 0 });
useEffect(() => {
const handleMouseMove = (e) => setPos({ x: e.clientX, y: e.clientY });
window.addEventListener("mousemove", handleMouseMove);
return () => window.removeEventListener("mousemove", handleMouseMove);
}, []);
return render(pos);
}
// Use it like this
<MouseTracker render={({ x, y }) => <p>Mouse at {x}, {y}</p>} />

Don’t throw away tools just because they’re not trendy.

6. The “Context Is for Settings, Not Your Whole App” Rant

I swear, if I see one more app using Context for everything, I’m switching to Vue out of spite.

Context is great for themes, auth, language — things that rarely change.

But if you’re using it to pass around dynamic state that updates often?

Prepare for performance hell.

Use state management libs for that. Or better yet, local state + props. Yeah, old-school. Because it works.

7. The “UseReducer for Complex State” Revelation

When your state looks like this:

const [state, setState] = useState({
step: 1,
error: null,
loading: false,
data: null,
});

It’s time.

useReducer isn’t just for Redux nerds. It’s for people who like control.

function reducer(state, action) {
switch (action.type) {
case "NEXT_STEP":
return { ...state, step: state.step + 1 };
case "SET_ERROR":
return { ...state, error: action.payload };
default:
return state;
}
}

You’ll feel like a wizard. Or at least, someone who doesn’t want to cry reading their code.

Finally, Code Like You’ll Maintain It Hungover

These patterns didn’t just make me a better React developer.

They made me less angry, more productive, and way more confident in my codebase.

React’s flexibility is a gift and a curse. You can write beautiful abstractions… or create a flaming trash pile.

Use patterns. Write for future-you. And please — don’t nest ternaries.

Got opinions? Good. Drop a comment, leave a clap, or argue with me in public.

I love a good React debate.

Just don’t tell me class components are better — we’re not doing that again.

Comments

Popular posts from this blog

Exploring Google’s New Gemini CLI: The Ultimate Open-Source Dev Tool

  Google quietly released a local AI agent that builds apps, debugs code, parses your repo, and fetches real-time data, right inside your terminal. And it’s completely free. This year, the most revolutionary developer tools I’ve used didn’t come with a splashy launch or billion-dollar hype. It came as a simple CLI: Gemini CLI, a terminal-based AI agent built on top of Google’s Gemini 2.5 Pro model . At first glance, it looks like a lightweight alternative to Claude Code. But after just 10 minutes of use, it became clear: this isn’t just a convenient utility. It’s a powerful local AI development assistant that can analyze, automate, and accelerate almost every part of your software workflow. And best of all? It’s fully open-source under the Apache 2.0 license It gives you up to 1,000 free requests per day It integrates with your local filesystem, IDE, and the web And it runs entirely in your terminal , no browser needed In this guide, I’ll show you what Gemini CLI is, how it works...

6 Essential JavaScript Concepts Every Developer Should Understand

It’s the only language I’ve used where [] == ![] it's true and where you can, typeof null and somehow get 'object' . But despite all its quirks (and there are many), there are a few core concepts that make life with JS not just easier, but saner. This isn’t some computer science flex. These are practical concepts that, once you understand them, make you write better, cleaner, and less buggy code. 1. Hoisting  Before you rage at your variables being undefined , understand this: JS hoists variable and function declarations to the top of their scope. But —  and this is important  —  only the declarations , not the assignments. Why? Because JS reads it like: This is also why let and const behave differently — they’re hoisted too, but live in the “Temporal Dead Zone” until declared. 2. Closures Closures are like little memory vaults for your functions. They allow functions to remember variables from the scope they were created in, even after that scope has gone. Why care? T...

Top 25 JavaScript Array Methods Every Developer Should Learn

  You wrote some code. You ran it. And then your array went from a list of users to an angry collection of undefined , NaN And more bugs than a summer camping trip. Staring at map , filter , and reduce like they were ancient scrolls written in Elvish. Copy-pasting from Stack Overflow like a caffeinated zombie. Wondering why the heck splice just murdered half my data. But here’s the truth: mastering arrays is non-negotiable. If you’re fumbling with arrays, you’re fumbling with everything . Web apps, APIs, UIs — they all depend on your ability to tame this glorious beast. So buckle up. I’m about to drop 25 methods that will make you look at arrays like a surgeon looks at a scalpel. Edited by me 1. map() - Because Loops Are for Cavemen You want to transform every item in an array? Don’t go forEach your way to hell. map It is concise, expressive, and doesn’t mutate your data. It’s like therapy for arrays. const names = [ 'alice' , 'bob' , 'charlie' ]; const u...