allantatter's avatar

React.js with Laravel

I would really like to start developing Laravel application with React.js but there are questions, how React should be actually integrated with Laravel? For example how to use React components on Laravel side, how to do server-side rendering with initial data? Maybe even routing? Are Laravel and React routings separate or are they somehow combined?

Maybe a single lesson or even series about React.js with Laravel?

0 likes
12 replies
tjm's avatar

You would use Laravel to provide the base view (index.blade.php) which would include the JS, but then after that all the views would be handled by React.

From there, you would use Laravel singularly as an API only. To get server-side rendering (Isomorphic) is another story. I'm curious to see PHP implementations of this using React PHP.

2 likes
allantatter's avatar

Maybe Blade templating engine should be improved to support React PHP usage within views so we would not be writing it like:

<?php

$rjs = new ReactJS($react_source, $app_source);
$rjs->setComponent('MyComponent', array(
    'any': 1,
    'props': 2));
brenelz's avatar

Just thought of an extension idea.

Maybe I should build a blade extension that supports reactjs. For example:

@reactjs(<MyComponent any="1" props="2"/>)

Just thinking out loud. This would only be for server side rendering of react.

Thoughts?

brenelz's avatar

I guess you could just do this otherwise:

{{ ReactJS::component('ComponentName') }}
2 likes
allantatter's avatar

I would prefer more React's jsx-like syntax. Then writing and using components would be similar in PHP and JavaScript.

1 like
saveroo's avatar

i know its probably late, but why dont you guys make lumen API ?

Please or to participate in this conversation.