2017 © Pedro Peláez
 

library react-laravel

Package to use ReactJS with Laravel

image

bitsoflove/react-laravel

Package to use ReactJS with Laravel

  • Tuesday, February 7, 2017
  • by stijntilleman
  • Repository
  • 6 Watchers
  • 0 Stars
  • 1,091 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 92 Forks
  • 0 Open issues
  • 16 Versions
  • 3 % Grown

The README.md

Code Climate Build Status, (*1)

react-laravel

With react-laravel you'll be able to use ReactJS components right from your Blade views, with optional server-side rendering, and use them on the client-side with React due to unobtrusive JavaScript., (*2)

Installation

V8js dependency

It's important to know that react-laravel has an indirect dependency of the v8js PHP extension., (*3)

You can see how to install it here: how to install v8js., (*4)

Composer

You just need to add this to your composer.json's "require":, (*5)

  "talyssonoc/react-laravel": "0.11"

Also you got to set the minimum-stability of your composer.json to dev, adding this:, (*6)

  "minimum-stability": "dev"

Then run:, (*7)

  $ composer update

After that you should add this to your providers at the config/app.php file of your Laravel app:, (*8)

  'React\ReactServiceProvider'

And then run:, (*9)

  php artisan vendor:publish

And the react.php file will be available at the config folder of your app., (*10)

Usage

After the installation and configuration, you'll be able to use the @react_component directive in your views., (*11)

The @react_component directive accepts 3 arguments:, (*12)

  @react_component(<componentName>[, props, options])

  //example
  @react_component('Message', [ 'title' => 'Hello, World' ], [ 'prerender' => true ])

  // example using namespaced component
  @react_component('Acme.Message', [ 'title' => 'Hello, World' ], [ 'prerender' => true ])
  • componentName: Is the name of the global variable that holds your component. When using Namespaced Components you may use dot-notation for the component name.
  • props: Associative of the props that'll be passed to your component
  • options: Associative array of options that you can pass to the react-laravel:
    • prerender: Tells react-laravel to render your component server-side, and then just mount it on the client-side. Default to true.
    • tag: The tag of the element that'll hold your component. Default to 'div'.
    • html attributes: Any other valid HTML attribute that will be added to the wrapper element of your component. Example: 'id' => 'my_component'.

All your components should be inside public/js/components.js (you can configure it, see below) and be global., (*13)

You must include react.js, react-dom.js and react_ujs.js (in this order) in your view. You can concatenate these files together using laravel-elixir., (*14)

react-laravel provides a ReactJS installation and the react_us.js file, they'll be at public/vendor/react-laravel folder after you install react-laravel and run:, (*15)

  $ php artisan vendor:publish --force

For using the files provided by react-laravel and your components.js file, add this to your view:, (*16)

  <script src="{{ asset('vendor/react-laravel/react.js') }}"></script>
  <script src="{{ asset('vendor/react-laravel/react-dom.js') }}"></script>
  <script src="{{ asset('js/components.js') }}"></script>
  <script src="{{ asset('vendor/react-laravel/react_ujs.js') }}"></script>

If you'll use a different version from the one provided by react-laravel (see composer.json), you got to configure it (see below)., (*17)

Configurations

You can change settings to react-laravel at the config/react.php file:, (*18)

  return [
    'source' => 'path_for_react.js',
    'dom-source' => 'path_for_react-dom.js',
    'dom-server-source' => 'path_for_react-dom-server.js',
    'components' => 'path_for_file_containing_your_components.js'
  ];

All of them are optional., (*19)

  • source: defaults to public/vendor/react-laravel/react.js.
  • dom-source: defaults to public/vendor/react-laravel/react-dom.js.
  • dom-server-source: defaults to public/vendor/react-laravel/react-dom-server.js.
  • components: defaults to public/js/components.js

Your components.js file should also be included at your view, and all your components must be at the window object., (*20)

Thanks

This package is inspired at react-rails., (*21)


Rollbar Error Tracking, (*22)

The Versions

07/02 2017

dev-master

9999999-dev

Package to use ReactJS with Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stijn Tilleman
by Talysson Oliveira

laravel react reactjs

21/06 2016

v1.2

1.2.0.0

Package to use ReactJS with Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stijn Tilleman
by Talysson Oliveira

laravel react reactjs

17/06 2016

v1.1

1.1.0.0

Package to use ReactJS with Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stijn Tilleman
by Talysson Oliveira

laravel react reactjs

17/06 2016

v1.0

1.0.0.0

Package to use ReactJS with Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stijn Tilleman
by Talysson Oliveira

laravel react reactjs

20/01 2016

v0.11

0.11.0.0

Package to use ReactJS with Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Talysson Oliveira

laravel react reactjs

02/10 2015

v0.10.2

0.10.2.0

Package to use ReactJS with Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Talysson Oliveira

laravel react reactjs

25/07 2015

v0.10.1

0.10.1.0

Package to use ReactJS with Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Talysson Oliveira

laravel react reactjs

13/07 2015

v0.10

0.10.0.0

Package to use ReactJS with Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Talysson Oliveira

laravel react reactjs

11/06 2015

v0.9.1

0.9.1.0

Package to use ReactJS with Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Talysson Oliveira

laravel react reactjs

27/05 2015

v0.9

0.9.0.0

Package to use ReactJS with Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Talysson Oliveira

laravel react reactjs

09/05 2015

v0.8

0.8.0.0

Package to use ReactJS with Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Talysson Oliveira

laravel react reactjs

23/04 2015

v0.7

0.7.0.0

Package to use ReactJS with Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Talysson Oliveira

laravel react reactjs

21/04 2015

v0.5

0.5.0.0

Package to use ReactJS with Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Talysson Oliveira

laravel react reactjs

19/04 2015

v0.3

0.3.0.0

Package to use ReactJS with Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Talysson Oliveira

laravel react reactjs

11/04 2015

v0.2

0.2.0.0

Package to use ReactJS with Laravel

  Sources   Download

MIT

The Requires

 

by Talysson Oliveira

laravel react reactjs

09/04 2015

v0.1

0.1.0.0

Package to use ReactJS with Laravel

  Sources   Download

MIT

The Requires

 

by Avatar talyssonoc