Skip to main content

10 Must-Know React Tricks for Beginners

 


It’s 2 AM, your code should work, but your component just stares back at you like a smug cat that knows you’re the problem.

You Google, Stack Overflow, maybe even beg ChatGPT (hey, we’ve all been there) — but nothing clicks.

I’ve been there. We all have.

But here’s the thing: professional React devs have a stash of sneaky tricks. Little power moves that make code cleaner, bugs rarer, and life easier.

They don’t teach these in tutorials. You only learn them in the trenches — or right here, if you’re lucky.

Let’s crack open the toolbox.


Photo by Lautaro Andreani on Unsplash

1. Use useRef For More Than Just DOM Access


Most beginners think useRef is just for grabbing DOM nodes. Cute.

const countRef = useRef(0);
useEffect(() => {
countRef.current++;
console.log('Rendered', countRef.current, 'times');
});

Boom. Now you’re tracking renders without triggering re-renders.

useRef Is your secret state that doesn't rerender the component? Like keeping a diary, your parents can’t…

Stop using useState for things that don’t affect UI. It’s overkill and slows things down.


2. Memoize Like You Mean It


If your app is slower than a snail on a treadmill, your components are probably re-rendering unnecessarily.

const memoizedValue = useMemo(() => computeHeavyStuff(data), [data]);

Or better yet:

const MyComponent = React.memo(({ data }) => {
// clean and mean
});

Sarcastic Truth Bomb: If you’re not memoizing, you’re just flexing how much CPU you can waste.


3. Destructure Props Like a Boss


Tired:

function Button(props) {
return <button>{props.label}</button>;
}

Wired:

function Button({ label }) {
return <button>{label}</button>;
}

Cleaner, shorter, and more readable. Destructuring is free readability. Use it.

4. Colocate State and Logic


Stop scattering state like breadcrumbs across files. Keep the state close to the component that needs it.

Why? Because debugging a component with state managed 3 parents up is like fixing a car through the exhaust pipe.

5. Short-Circuit Rendering FTW


{isLoggedIn && <Dashboard />}

No need for clunky ternaries:

{isLoggedIn ? <Dashboard /> : null}

Unless you like writing extra code for no reason.

6. Conditional ClassNames Like a Pro


Ever seen this mess?

className={isActive ? 'btn active' : 'btn'}

Try this instead:

npm install classnames
import classNames from 'classnames';
className={classNames('btn', { active: isActive })}

Pro Move: Clean, scalable, readable.


7. Avoid Anonymous Functions in JSX


<button onClick={() => doSomething()}>Click</button>

Looks fine… until you realize it creates a new function every render.

Do this:

function handleClick() {
doSomething();
}
<button onClick={handleClick}>Click</button>

Think Ahead: Performance isn’t an issue — until it is.


8. Know When to Use Context — and When NOT To


Context is powerful. Also dangerously overused.

Use it for themes, auth, and language. Don’t use it to pass everything everywhere. That’s prop drilling in disguise.

If your context is 5 levels deep and triggers 10 renders when one value changes — you messed up.


9. Custom Hooks = Your Superpower


function useLocalStorage(key, initialValue) {
const [value, setValue] = useState(() => {
const item = window.localStorage.getItem(key);
return item ? JSON.parse(item) : initialValue;
});
useEffect(() => {
window.localStorage.setItem(key, JSON.stringify(value));
}, [key, value]);
  return [value, setValue];
}

Reusability. Clean code. Fewer bugs. What’s not to love?

10. Lint Like a Lunatic


Install ESLint. Use Airbnb’s config. Set your editor to scream at you when you write bad code.

npx eslint --init

Real Talk: Linting catches 80% of dumb mistakes before they hit production.


Finally, React Doesn’t Suck — Your Habits Might


React isn’t hard. What’s hard is unlearning bad habits and leveling up your thinking. These 10 tricks? They’re just the tip of the iceberg.

Got your hot take? Angry disagreement? Mild appreciation?

Drop a comment. Smash that clap. Or roast me in the replies. Just don’t walk away without sharing your thoughts.


Stay curious, stay sarcastic, and keep building.

Don’t keep it to yourself. Share it with your team and level up together!



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...