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

CSS only Click-handlers You Might not be using, but you should

  You’re building a simple website, a good-looking landing page with a “See More” button. Instinctively, you reach for JavaScript to handle the button click event. But wait — what if I told you that CSS alone could do the job? Yes. CSS is often underestimated, but it can handle click interactions without JavaScript. In this guide, you’ll learn how to create CSS-only click handlers using the :target pseudo-class, and explore scenarios where this approach makes perfect sense. The :target Pseudo-Class CSS offers several pseudo-classes that let you style elements based on different states ( :hover , :focus , :checked ). But there’s one you might not have used before —  :target . The :target pseudo-class applies styles to an element when its ID matches the fragment identifier in the URL (the part after # ). This behavior is commonly seen when clicking an anchor link that jumps to a section on the same page. Here’s a simple example : <a href="#contact">Go to Contact</...

The 10 Best New CSS Features in 2025 Already Supported in All Major Browsers

  CSS keeps evolving with new capabilities that make our work faster, cleaner, and more powerful. Thanks to the latest browser advances (Baseline 2024), many fresh features now work across all major engines. Below are ten highlights you can start using right away. Do you want more? Let’s check out my project, CSSToday: csstoday.dev/ 1. Scrollbar-Gutter & Scrollbar-Color When a browser displays a scrollbar, the layout can shift as space is taken up. With scrollbar-gutter , you can preserve scrollbar space even before scrolling begins: .scrollable {   scrollbar-gutter : stable both-edges; } You can also style your scrollbars with scrollbar-color : .scrollable {   scrollbar-color : #444 #ccc ; } This ensures a consistent look and prevents layout jumps. What it’s good for ✅ scrollbar-gutter keeps layouts stable by reserving space for a scrollbar, preventing annoying shifts when the scrollbar appears. scrollbar-color lets you style the scrollbar’s track and thumb, en...

Sharpen Your Front-End Skills: Quick HTML, CSS & React Interview Challenges

  The source of this image is Chat GPT based on writing! Are you preparing for front-end developer interviews and looking for practical, hands-on ways to improve your HTML, CSS, and React skills? Whether you’re a beginner aiming to build confidence or an experienced developer brushing up on UI skills, small, targeted challenges can make a huge difference. In this article, I’ll walk you through some of the best free and low-cost resources that offer real-world front-end tasks — perfect for interview prep, portfolio building, and daily practice. 1. Frontend Mentor frontendmentor.io Frontend Mentor is one of the most popular platforms for hands-on HTML, CSS, and JavaScript challenges. You get beautifully designed templates (in Figma or image formats) and are asked to bring them to life using clean code. The platform offers difficulty levels ranging from newbie to expert, and it’s perfect for practicing responsiveness and semantic HTML. Bonus : You can even filter for React-based ...