laravel/blank-react-starter-kit
Minimal Laravel + React starter kit using Inertia, Vite, TypeScript, and Tailwind. Build SPA-like React apps with classic Laravel routing and controllers. No authentication scaffolding included—start from a clean, modern baseline.
Installation
composer create-project laravel/blank-react-starter-kit my-app
cd my-app
npm install
npm run dev
First Use Case: Rendering a React Page
// routes/web.php
Route::get('/dashboard', function () {
return Inertia::render('Dashboard');
});
// resources/js/Pages/Dashboard.tsx
export default function Dashboard() {
return <h1 className="text-2xl font-bold">Welcome to Dashboard</h1>;
}
/dashboard to see the page render.Key Directories to Explore
resources/js/Pages/ – React components (Inertia pages).resources/js/Layouts/ – Shared layouts (e.g., AppLayout.tsx).routes/web.php – Server-side routes mapped to React pages.vite.config.ts – Vite configuration (asset handling, plugins).Page-Based Routing with Inertia
// routes/web.php
Route::get('/profile', [ProfileController::class, 'show']);
// resources/js/Pages/Profile.tsx
export default function Profile({ user }: { user: User }) {
return <div>{user.name}</div>;
}
State Management
useState, useEffect) for component-scoped state.usePage for shared data (e.g., auth user).
const { auth } = usePage().props;
axios (pre-configured) for backend communication.
const response = await axios.get('/api/data');
Form Handling
const form = useForm({
email: '',
});
form.post('/submit', {
preserveScroll: true,
});
Layouts and Shared UI
AppLayout for consistent headers/footers:
export default function Dashboard() {
return (
<AppLayout>
<h1>Dashboard</h1>
</AppLayout>
);
}
resources/js/Layouts/Guest.tsx for auth-agnostic pages.API Integration
axios.get('/api/user', {
headers: { Authorization: `Bearer ${token}` },
});
Tailwind CSS
tailwind.config.js for custom themes:
module.exports = {
theme: {
extend: {
colors: {
primary: '#3b82f6',
},
},
},
};
TypeScript
Page interface:
interface Props {
user: { name: string };
}
export default function Page({ user }: Props) { ... }
Environment Variables
import.meta.env (Vite) or config() (Laravel):
const apiUrl = import.meta.env.VITE_API_URL;
Testing
@inertiajs/react test utilities or React Testing Library.HttpTests for API routes.Inertia Page Mismatch
Inertia::render('Page') but resources/js/Pages/Page.tsx doesn’t exist.Vite/HMR Delays
npm run dev) or check browser console for errors.CSRF Token Errors
419 (CSRF mismatch).{{ csrf_token() }} is in Laravel blade templates (if using traditional forms) or rely on Inertia’s automatic handling for SPA forms.TypeScript Errors
Property 'xxx' does not exist on type 'PageProps'.PageProps interface in resources/js/shims.d.ts:
declare global {
interface PageProps {
user: User;
}
}
Asset Loading
npm run build and ensure public/build assets are linked in Laravel’s app.blade.php:
@vite(['resources/js/app.tsx', 'resources/css/app.css'])
Inertia Logs
config/inertia.php:
'debug' => env('APP_DEBUG', true),
storage/logs/laravel.log) for Inertia errors.Network Tab
Vite Dev Server
npm run dev -- --force.Custom Inertia Responses
HandleInertiaRequests middleware to modify responses:
public function share(Request $request): array
{
return array_merge(parent::share($request), [
'appName' => 'MyApp',
]);
}
Plugin Integration
vite.config.ts:
import laravel from 'laravel-vite-plugin';
export default defineConfig({
plugins: [
laravel({
input: ['resources/js/app.tsx'],
refresh: true,
}),
// Add other plugins (e.g., @vitejs/plugin-react)
],
});
Authentication
composer require laravel/fortify
php artisan vendor:publish --provider="Laravel\Fortify\FortifyServiceProvider"
Inertia::auth() in middleware and usePage().props.auth in React.Internationalization (i18n)
laravel-lang or vue-i18n with Inertia:
import { usePage } from '@inertiajs/react';
const { __ } = usePage().props;
How can I help you explore Laravel packages today?