React.js is a powerful JavaScript library that has revolutionized front-end development. Known for its component-based architecture, virtual DOM, and flexibility, React makes it easy to build scalable and interactive user interfaces.
In this post, we’ll break down the core concepts of React that every developer should master.
React is an open-source JavaScript library developed by Facebook for building user interfaces, especially single-page applications (SPAs). It focuses on rendering the view layer and enables you to build reusable UI components.
JSX is a syntax extension that lets you write HTML-like code within JavaScript:
const element = <h1>Hello, React!</h1>;
It makes your UI code more readable and expressive, and it’s compiled into JavaScript under the hood.
React encourages developers to build UIs using components, which are reusable, self-contained pieces of code.
function Greeting() {
return <h2>Hello from React!</h2>;
}
class Greeting extends React.Component {
render() {
return <h2>Hello from a class component!</h2>;
}
}
Components can accept inputs called props and manage their own state.
Props (short for properties) let you pass data from a parent component to a child component:
function Welcome(props) {
return <h1>Hello, {props.name}!</h1>;
}
// Usage:
<Welcome name="Developer" />
Props are read-only, which helps maintain predictable data flow.
State lets a component hold and manage data that can change over time.
import { useState } from 'react';
function Counter() {
const [count, setCount] = useState(0);
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>Click me</button>
</div>
);
}
State is managed internally and is used to control component behavior and rendering.
React uses a consistent and simple approach to handle DOM events:
function handleClick() {
alert('Button clicked!');
}
<button onClick={handleClick}>Click Me</button>
You can pass functions as event handlers just like in standard JavaScript, but using camelCase syntax.
You can render components conditionally using JavaScript expressions:
{isLoggedIn ? <Logout /> : <Login />}
Or:
{show && <p>Now you see me!</p>}
This gives you full control over what gets rendered based on the app's state.
Rendering dynamic lists is simple with the map()
function:
const items = ['React', 'Vue', 'Angular'];
<ul>
{items.map((item, index) => (
<li key={index}>{item}</li>
))}
</ul>
Keys help React identify which items have changed or been added/removed for efficient updates.
The useEffect
hook lets you run side effects like API calls, timers, or subscriptions:
import { useEffect } from 'react';
useEffect(() => {
console.log('Component mounted or updated!');
}, []);
It replaces traditional lifecycle methods like componentDidMount
and componentDidUpdate
.
React Router lets you implement client-side routing easily:
import { BrowserRouter, Routes, Route } from 'react-router-dom';
<BrowserRouter>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/about" element={<About />} />
</Routes>
</BrowserRouter>
This allows your app to be a full-featured single-page application without full page reloads.
There are two popular tools to set up a React project:
✅ Create React App (CRA):
npx create-react-app my-app
✅ Vite (Fast & Modern):
npm create vite@latest my-app -- --template react
Both provide a streamlined development environment with hot-reloading and support for JSX.
React is a modern, flexible, and efficient tool for building powerful front-end applications. By mastering these core concepts—JSX, components, props, state, hooks, and routing—you’ll be well-equipped to create responsive and dynamic UIs.
🚀 Ready to go further? Stay tuned for deep dives into advanced topics like React Hooks, Context API, Redux, and performance optimization in future posts!
Full Stack Developer skilled in React.js, Node.js, and building scalable web apps. Expert in REST APIs, Redux, MySQL, and AWS integration. Passionate about clean code and seamless user experiences.