When I first looked at React after years of PHP and WordPress development, the mental model felt completely foreign. Where are the page templates? Why is the JavaScript in the markup? What even is a component? It took me longer to get comfortable with React than it should have, because most tutorials assume you're coming from a JavaScript background.
This guide explains React in terms PHP developers already understand. If you know PHP functions, classes, and how WordPress template files work, React is more familiar than it looks.
The Core Mental Model: Components Are PHP Functions
A React component is a function that receives data (props) and returns markup (JSX). If you've written a WordPress template function that accepts arguments and outputs HTML, you already understand the concept:
// PHP function you already know:
function render_service_card( $title, $description, $icon ) {
return "<div class='card'><h3>$title</h3><p>$description</p></div>";
}
// React equivalent:
function ServiceCard({ title, description, icon }) {
return (
<div className="card">
<h3>{title}</h3>
<p>{description}</p>
</div>
);
}
Same idea. Different syntax. The JSX (the HTML-looking syntax inside JavaScript) compiles down to regular JavaScript function calls — it's syntactic sugar, not a new language.
Props Are Function Arguments
Props in React are the equivalent of function arguments in PHP. They're how you pass data into a component. Treat them as read-only — just like you wouldn't modify a function's parameters inside the function body.
The parent component controls what props it passes down, just like the code calling a PHP function controls the arguments it passes in. This is called "one-way data flow" in React terminology — data flows down from parent to child, never up.
State Is Like a Variable That Triggers a Re-render
This is where React diverges from PHP. In PHP, when you change a variable, nothing happens visually — the page is already rendered. In React, components live in the browser and can update without a page reload.
useState is the hook that makes this work. When a state variable changes, React automatically re-renders the component with the new value:
// PHP: change a variable, nothing updates
$count = 0;
$count++; // nothing visible happens
// React: change state, component re-renders automatically
const [count, setCount] = useState(0);
setCount(count + 1); // component re-renders with count = 1
Think of state as a PHP session variable that, when changed, automatically refreshes just the relevant piece of the page — not the whole page.
useEffect Is Your Init and Lifecycle Hook
In WordPress plugin development, you use add_action('init', ...) or add_action('wp_enqueue_scripts', ...) to run code at specific lifecycle points. React's useEffect hook is the equivalent — it runs code at specific points in a component's lifecycle.
The most common use case: fetching data from an API when a component loads:
useEffect(() => {
// Runs after the component renders — like WordPress 'init' hook
fetch('/api/projects')
.then(r => r.json())
.then(data => setProjects(data));
}, []); // Empty array = run once on mount, like 'init'
Connecting React to a Laravel API
The architecture I use most often: Laravel as the backend API, React as the frontend SPA. Laravel handles data, auth, and business logic. React handles the UI. They communicate via a REST API secured with Laravel Sanctum.
The setup: React (Vite) runs on port 5173 in development, proxies API calls to Laravel on port 8000. In production, React builds to static files served by Nginx, which proxies /api/* routes to Laravel.
For data fetching, I use React Query (TanStack Query) — it handles caching, background refetching, loading states, and error states with far less code than raw useEffect. If you're building anything beyond a simple prototype, React Query is worth adding immediately.
When to Use React vs WordPress/PHP
React is not the right tool for every project. My decision framework:
- Marketing sites, blogs, brochure sites → WordPress. React is overkill. PHP renders HTML server-side, which is better for SEO and simpler to maintain.
- Dashboards, admin panels, data-heavy interfaces → React. Real-time updates, complex filtering, and interactive tables are where React's component model shines.
- eCommerce → WooCommerce for most cases. React-based headless commerce (WooCommerce + React frontend) only makes sense for high-traffic stores with significant UX requirements that WooCommerce's frontend can't meet.
- Web applications with rich interactivity → React + Laravel API is an excellent combination.
Getting Started Without the Overwhelm
The React ecosystem has a reputation for being overwhelming — and it deserves it. My recommendation for PHP developers starting with React: learn in this order.
- Vite + React setup (10 minutes)
- Components and props — build 5 simple components
- useState — build a counter, then a form
- useEffect + fetch — call a real API
- React Router — multi-page navigation
- React Query — replace raw useEffect for data fetching
Skip Redux, Context API, and Next.js until you're comfortable with the basics. The ecosystem is large, but the core concepts are small. Master those first.
Building a React frontend for a Laravel API? Take a look at my recent projects or get in touch — happy to discuss the architecture.
Related Service
💻 Web Development
Custom websites and web applications built with PHP, Laravel, WordPress, and React — fast, secure, scalable, and tailored to your business goals.
Explore Web Development →