Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here
Premium Members Only
Join to unlock this tutorial and all of our courses.
Tutorial Premium Tutorial

React.js in Laravel: Main Things You Need to Know

July 07, 2025
14 min read

React.js is the most popular front-end JS framework. There are a few ways to use React in Laravel projects, and in this tutorial, we will cover so-called RILT stack with examples, also touching the alternative of using Next.js with Laravel API.

So, if you're a Laravel back-ender and want to get familiar with React, let's begin.


Setting Up Your First RILT Stack Project

The RILT stack (React, Inertia, Laravel, Tailwind) comes pre-configured in Laravel 12's React starter kit with React 19, TypeScript, Tailwind 4, and shadcn/ui components. Here's how to get started:

laravel new my-react-app
 
# Choose React when prompted for starter kit
 
# Navigate to project and install dependencies
cd my-react-app
npm install && npm run build
composer run dev

Your application will be available at http://localhost:8000 with authentication pages already working.


Understanding Your First React Component

Let's examine a simple React component to understand the fundamentals. The majority of frontend code is located in the resources/js directory.

resources/js/pages/welcome.tsx:

import { Head, usePage } from '@inertiajs/react';
import { type SharedData } from '@/types';
 
export default function Welcome({
laravelVersion,
phpVersion,
message
}: {
laravelVersion: string;
phpVersion: string;
message: string;
}) {
const { auth } = usePage<SharedData>().props;
 
return (
<>
<Head title="Welcome" />
<div className="bg-gray-50 text-black/50 dark:bg-black dark:text-white/50">
<div className="relative min-h-screen flex flex-col items-center justify-center">
<div className="relative w-full max-w-2xl px-6 lg:max-w-7xl">
<header className="grid grid-cols-2 items-center gap-2 py-10 lg:grid-cols-3">
<h1 className="text-3xl font-bold">
Hello from React!
</h1>
{auth.user ? (
<span>Welcome back, {auth.user.name}!</span>
) : (
<span>Please log in to continue</span>
)}
</header>
 
<main className="mt-6">
<p>{message}</p>
<p>Laravel version: {laravelVersion}</p>
<p>PHP version: {phpVersion}</p>
</main>
</div>
</div>
</div>
</>
);
}

Component Breakdown

Import Statements:

  • Head from Inertia handles page metadata like title and meta tags
  • PageProps provides TypeScript typing for component props

Component Function:

  • Receives props including authentication data and version information
  • Uses destructuring to extract specific props with TypeScript typing

JSX Return:

  • Wrapped in React Fragment (<>...</>) to return multiple elements
  • Uses Tailwind CSS classes for styling
  • Conditional rendering shows different content for authenticated users

How Inertia.js Bridges Laravel and React

Inertia.js allows you to...

Premium Members Only

This advanced tutorial is available exclusively to Laravel Daily Premium members.

Premium membership includes:

Access to all premium tutorials
Video and Text Courses
Private Discord Channel

Comments & Discussion

RA
Richard A. Hoyle ✓ Link copied!

I tried to follow along but the version you are using and the one I have “inertiajs/inertia-Laravel 2.0.3, on Laravel framework 12.20.0 are just so different that I can’t do so. can you update this project please?

I am using Laravel Herd Pro to create the project

N
Nerijus ✓ Link copied!

I don't understand what you want to update? This tutorial is only a week old, of course, it uses inertia v2.

RA
Richard A. Hoyle ✓ Link copied!

This is strata out the box sort speak, running Herd and chousing sites/add/new Laravel project then next. then chousing React next giving it a name and creating the project.

The first thang is you have a file: app/Http/Controllers/WelcomeController.php that does not exist in my version.

Next the routings are different you have:

Route::get('/', [WelcomeController::class, 'index'])->name('welcome');

and what I have is:

Route::get('/', function () { return Inertia::render('welcome'); })->name('home');

Next How Do I create the resources/js/pages/tasks/create.tsx file?
This is my first time working with React and I do not know what command to use to create the different files for it.

P.S. this is on a windows 11 operating system.

N
Nerijus ✓ Link copied!

Do you know how to create a file manually? That's how. There's no command to create js files. As for controller, create it. You must know how laravel works first.

A
adminxs ✓ Link copied!

Dear Nerijus, please be more user / developer friendly on your comments so to keep a healthy communication environment within the thread in continuation. In this case the surtain tutorial will keep it's pace to help the others to evolve and spread positive feedback for the same course.

A
anjanesh ✓ Link copied!

composer run dev Did you mean npm run dev ?

N
Nerijus ✓ Link copied!

No, it's correct. composer run dev does more. Check here: https://github.com/laravel/laravel/blob/12.x/composer.json#L50

A
anjanesh ✓ Link copied!

Oh - this is new to me, thanks.

A
anjanesh ✓ Link copied!

In the My Tasks page (of react and Inertia) does this list all tasks or only the logged-in user's tasks ?

M
Modestas ✓ Link copied!

Only the logged in person, as we have a condition there:

        $tasks = Task::where('user_id', $request->user()->id)->get();
A
anjanesh ✓ Link copied!

Thats mentioned in Alternative: Laravel API + Next.js Frontend - but where is it mentioned in InertiaJS example code ?

N
Nerijus ✓ Link copied!

why does it matter? Controller code would be the same