Back to docs

Laravel React Make

Artisan command to generate React components with support for TypeScript.

Laravel Support

Laravel Laravel React Make
10, 9 3
9, 8 2
8, 7, 6 1

Installation

In your Laravel directory install via Composer.

composer require --dev fsac/laravel-react-make

Basic Usage

Generate a React function component in the file MyComponent.js under resources/js/components.

php artisan make:react PrimaryButton
# -> resources/js/components/PrimaryButton.js

You may also include subdirectories:

php artisan make:react buttons/Primary
# -> resources/js/components/buttons/Primary.js

Advanced Usage

Use .jsx file extension instead of the default .js. The short version -x may also be used:

php artisan make:react --jsx PrimaryButton
# -> resources/js/components/PrimaryButton.jsx

Generate a React class component. The short version -c may also be used.

php artisan make:react --class MyComponent

TypeScript

The command also supports generating TypeScript components. The short version -t may also be used:

php artisan make:react --typescript PrimaryButton
# -> resources/js/components/PrimaryButton.ts

When used in combination with the --jsx option the .tsx suffix will be used. The following example uses short option variants:

php artisan make:react -tx PrimaryButton
# -> resources/js/components/PrimaryButton.tsx

You may also generate TypeScript class components. The following example uses short option variants:

php artisan make:react -tc PrimaryButton
# -> resources/js/components/PrimaryButton.ts

Customising Stubs

If you'd like to customise the default templates used to generate components you may publish them to the stubs directory:

php artisan vendor:publish --tag react-stub