All Key React Concepts Explained - Featured Image
Web development6 min read

All Key React Concepts Explained

Have you ever stared at React code wondering what the heck reconciliation or state management actually means? Yeah, me too. After spending countless late nights debugging and scrolling through Stack Overflow, I figured it was time to break down these concepts for fellow developers who just want things explained in details.

React Components

Think of components as LEGO pieces. Each piece has a specific purpose, but when combined, they create something awesome. Components are just reusable chunks of code that return something to show on your screen.

I remember my first component looked something like this:

function Greeting(props) {
  return <h1>Hey there, {props.name}!</h1>;
}

Pretty simple, right? Just like a JavaScript function that returns HTML (well, JSX, but we'll get to that).

Pro tip: Stick with functional components these days. Class components are like those baggy jeans from the 2000s – they still work, but nobody's really using them anymore.

JSX in React

JSX lets you write what looks like HTML directly in your JavaScript files. The first time I saw it, I thought someone had accidentally pasted HTML into their JS file!

<button className="fancy-btn">Click me!</button>

Notice that className instead of class? That's because JSX follows camelCase conventions like JavaScript, not HTML. Took me about 50 compilation errors to remember that one.

And if you're using TypeScript (which, trust me, will save you tons of debugging headaches later), you'll be working with TSX files. They're basically the same thing but with type checking:

interface UserProps {
  name: string;
  age: number;
}

const UserGreeting = (props: UserProps) => {
  return <p>Hi {props.name}, you don't look {props.age} at all!</p>;
};

React Fragments

Ever tried returning multiple elements from a component only to get an error? That's where fragments come in. They're like invisible containers that group stuff without adding extra divs to your DOM.

const Navbar = () => {
  return (
    <>
      <Logo />
      <Menu />
      <SearchBar />
    </>
  );
};

I used to wrap everything in divs until my DOM looked like a nested Russian doll. Fragments cleaned that up real quick.

React Props

Props are basically how you pass data between components. Think of them as arguments to your component functions.

function Welcome(props) {
  return <h1>Welcome back, {props.username}!</h1>;
}

// Then somewhere else:
<Welcome username="dev_rockstar" />

The data only flows one way (parent to child), which confused me at first. But this actually prevents a lot of bugs – trust me on this one.

React State

State is how components remember stuff. My favorite analogy is thinking of state like your component's short-term memory.

const [darkMode, setDarkMode] = useState(false);

This line says "I want to remember if we're in dark mode, and right now we're not." When you call setDarkMode(true), React remembers the new value and updates the screen.

I once had a bug where I was directly modifying state variables instead of using the setter function. Spent three hours debugging before I realized my mistake. Don't be like me.

React Lifecycle Methods

Every component goes through phases:

  • It's born (mounting)

  • It changes (updating)

  • It dies (unmounting)

With hooks, you can tap into these phases. For example, useEffect lets you run code when your component mounts or when specific values change.

Purity in React

A pure component always renders the same output for the same props. This predictability makes React fast and reliable.

I learned this lesson the hard way when I had a component that was using some global variable outside its scope. The component would render differently depending on when it was called, making debugging nearly impossible.

React Strict Mode

Strict Mode is like having a really annoying but helpful friend who points out all your mistakes before they become problems. It shows warnings in your console about potential issues.

<React.StrictMode>
  <App />
</React.StrictMode>

When I first used Strict Mode, my console lit up like a Christmas tree with warnings. It was embarrassing but fixed a ton of bugs before they happened.

React Hooks

Hooks let you use state and other React features without writing class components. The most common one is useState, but there are several others like useEffect, useContext, and useRef.

function ColorPicker() {
  const [color, setColor] = useState("blue");
  
  return (
    <>
      <h1 style={{ color }}>I love this {color} text!</h1>
      <button onClick={() => setColor("red")}>Red</button>
      <button onClick={() => setColor("blue")}>Blue</button>
      <button onClick={() => setColor("green")}>Green</button>
    </>
  );
}

The rules of hooks tripped me up at first: only call them at the top level, never in conditions or loops. Once I got that, they became second nature.

Context API

Context lets you pass data through your component tree without manually passing props down at every level. It's perfect for things like themes, user data, or language preferences that many components need.

// Create the context
const ThemeContext = createContext();

// Provider component
function App() {
  const [theme, setTheme] = useState("light");
  
  return (
    <ThemeContext.Provider value={{ theme, setTheme }}>
      <Header />
      <MainContent />
      <Footer />
    </ThemeContext.Provider>
  );
}

// Consumer component (anywhere in the tree)
function ThemeToggle() {
  const { theme, setTheme } = useContext(ThemeContext);
  
  return (
    <button onClick={() => setTheme(theme === "light" ? "dark" : "light")}>
      Switch to {theme === "light" ? "dark" : "light"} mode
    </button>
  );
}

Before I discovered Context, I was passing props through 5+ levels of components. My code looked ridiculous.

Lists and Keys

When rendering lists in React, you need to give each item a unique identifier (key) so React knows which items changed, were added, or removed.

function ShoppingList({ items }) {
  return (
    <ul>
      {items.map(item => (
        <li key={item.id}>{item.name} - ${item.price}</li>
      ))}
    </ul>
  );
}

I made the mistake of using array indices as keys once, and my list went haywire when items were reordered. Don't use index as keys unless your list is static and won't change.

Forms

There are two ways to handle forms in React:

Controlled Components: React manages the form data.

function NameForm() {
  const [name, setName] = useState("");
  
  const handleSubmit = (e) => {
    e.preventDefault();
    alert(`Hello, ${name}!`);
  };
  
  return (
    <form onSubmit={handleSubmit}>
      <input 
        type="text" 
        value={name} 
        onChange={e => setName(e.target.value)} 
      />
      <button type="submit">Greet Me</button>
    </form>
  );
}

Uncontrolled Components: The DOM handles the form data.

function SimpleForm() {
  const inputRef = useRef();
  
  const handleSubmit = (e) => {
    e.preventDefault();
    alert(`Hello, ${inputRef.current.value}!`);
  };
  
  return (
    <form onSubmit={handleSubmit}>
      <input type="text" ref={inputRef} />
      <button type="submit">Greet Me</button>
    </form>
  );
}

I prefer controlled components because they make validation easier, but uncontrolled components are simpler for basic forms.

React Router

React Router lets you handle navigation in your single-page application. First, install it:

npm install react-router-dom

Then set up your routes:

import { BrowserRouter, Routes, Route } from "react-router-dom";

function App() {
  return (
    <BrowserRouter>
      <Routes>
        <Route path="/" element={<Home />} />
        <Route path="/about" element={<About />} />
        <Route path="/contact" element={<Contact />} />
        <Route path="*" element={<NotFound />} />
      </Routes>
    </BrowserRouter>
  );
}

I remember trying to build my own routing system before discovering React Router. Save yourself that headache.

Conclusion

The best way to learn React isn't by memorizing these concepts but by actually building stuff. Start with a simple project, mess up, Google your errors, and learn from them. That's how I learned, and despite all the frustrations along the way, it's been worth it. React makes building modern web apps so much more enjoyable once you get past the initial learning curve.

Posted on: 14/3/2025

hassaankhan

Frontend Developer — UI/UX Enthusiast and building scalable web apps

Posted by





Subscribe to our newsletter

Join 2,000+ subscribers

Stay in the loop with everything you need to know.

We care about your data in our privacy policy

Background shadow leftBackground shadow right

Have something to share?

Write on the platform and dummy copy content

Be Part of Something Big

Shifters, a developer-first community platform, is launching soon with all the features. Don't miss out on day one access. Join the waitlist: