• Stars
    star
    900
  • Rank 49,076 (Top 1.0 %)
  • Language
    PHP
  • Created about 9 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Package for using ReactJS with Laravel

Code Climate Build Status

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.

Installation

V8js dependency

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

You can see how to install it here: how to install v8js.

Composer

Set the minimum-stability of your composer.json to dev, adding this:

  "minimum-stability": "dev"

Then run:

  $ composer require talyssonoc/react-laravel:0.11

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

  'React\ReactServiceProvider'

And then run:

  php artisan vendor:publish

And the react.php file will be available at the config folder of your app.

Usage

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

The @react_component directive accepts 3 arguments:

  @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.

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.

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:

  $ php artisan vendor:publish --force

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

  <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).

Configurations

You can change settings to react-laravel at the config/react.php file:

  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.

  • 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. Multiple components files may be specified here.

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

Thanks

This package is inspired at react-rails.

More Repositories

1

node-api-boilerplate

DDD/Clean Architecture inspired boilerplate for Node web APIs
TypeScript
3,289
star
2

react-katex

Display math in TeX with KaTeX and ReactJS
JavaScript
410
star
3

structure

A simple schema/attributes library built on top of modern JavaScript
JavaScript
301
star
4

CommonRegexJS

Find a lot of kinds of common information in a string. CommonRegex port for JavaScript
JavaScript
150
star
5

react-redux-ddd

Just an experiment
JavaScript
88
star
6

CommonRegexRuby

Find a lot of kinds of common information in a string. CommonRegex port for Ruby
Ruby
79
star
7

emittr

A Ruby event emitter implementation.
Ruby
71
star
8

i18node

I18n library for Node.js with support for plurals and genders
JavaScript
65
star
9

jsT9

A text-prediction JavaScript tool
JavaScript
64
star
10

WolverineJS

Useful library for server-side logging
JavaScript
39
star
11

react-predict

ReactJS for input with autocomplete based on list of words
JavaScript
36
star
12

php-babel-transpiler

Transform JavaScript with Babel from PHP
PHP
31
star
13

CommonRegexJava

CommonRegex port for Java
Java
20
star
14

isomorphic-alt-boilerplate

Isomorphic app boilerplate with React + Alt
JavaScript
16
star
15

frontend-architecture-jsconf-chile-2023

Frontend architecture - JSConf Chile 2023
TypeScript
16
star
16

react-laravel-example

An example of how to use react-laravel package
PHP
14
star
17

backbone-dispatcher

A Flux dispatcher for using with Backbone
JavaScript
14
star
18

jsAutoSuggest

Autosuggest JavaScript tool using jsT9
JavaScript
11
star
19

jquery-flux-todo

Experiment on creating a jQuery app with Flux architecture
JavaScript
7
star
20

angular-blog-app

Simple blog app for learning Angular
JavaScript
6
star
21

generator-iso-alt

Generator for isomorphic flux apps with React and Alt
JavaScript
6
star
22

Fraction

C++ lib for use of Fractions instead of float type
C++
4
star
23

umd-templates

UMD pattern templates for gulp-umd compliants
JavaScript
4
star
24

ruby_ddd

Just an experiment
Ruby
3
star
25

wingpanel-indicator-services

Vala
3
star
26

flux-tracker

JavaScript
3
star
27

react-unit-testing

An example of how to unit test React components
JavaScript
3
star
28

joi-repro

JavaScript
2
star
29

componentized-angular

JavaScript
2
star
30

drunk-postman

JavaScript
2
star
31

di-brown-bag

JavaScript
2
star
32

quake-log-parser-haskell

Haskell
2
star
33

phactory-laravel

Use Phactory inside Laravel
PHP
2
star
34

front-end-boilerplate

My boilerplate for front-end projects
JavaScript
2
star
35

cordova-hooks

My personal Cordova/Phonegap hooks
JavaScript
2
star
36

isomorphic-experiences

Experiences for isomorphic approaches
PHP
2
star
37

ee

Experimental event emitter
JavaScript
2
star
38

jquery-pluginconfig

A jQuery plugin that help use data attributes for configuration
JavaScript
2
star
39

room-word-sample

Kotlin
1
star
40

fluxmaker

[WIP]
JavaScript
1
star
41

ruby_error_repository_example

Ruby
1
star
42

express-ajax-only

Express middleware for only accept AJAX request for a given URL
JavaScript
1
star
43

MaMoney

Money control app
Ruby
1
star
44

enemyBoxes

jQuery extensions for make a set of checkboxes that can't be checked at the same time.
JavaScript
1
star
45

c_ddd

It's an experience, don't take it seriously
C
1
star
46

java_ddd

This is just an experience for a study group
Java
1
star
47

express-secure-only

Express middleware for only accept secure requests (i.e. HTTPS requests)
JavaScript
1
star
48

reproduce-sequelize-bug

JavaScript
1
star
49

BackboneFluxTests

Tests mixing Backbone and Flux architecture
JavaScript
1
star