talyssonoc/react-laravel
Composer 安装命令:
composer require talyssonoc/react-laravel
包简介
Package to use ReactJS with Laravel
README 文档
README
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 thepropsthat'll be passed to your componentoptions: Associative array of options that you can pass to thereact-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 topublic/vendor/react-laravel/react.js.dom-source: defaults topublic/vendor/react-laravel/react-dom.js.dom-server-source: defaults topublic/vendor/react-laravel/react-dom-server.js.components: defaults topublic/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.
talyssonoc/react-laravel 适用场景与选型建议
talyssonoc/react-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.94k 次下载、GitHub Stars 达 893, 最近一次更新时间为 2015 年 04 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「react」 「reactjs」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 talyssonoc/react-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 talyssonoc/react-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 talyssonoc/react-laravel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Async Reactive Postgres Driver for PHP (Non-blocking)
Yii2 asset collection of useful JavaScript libraries
Client and Server-side React rendering for CraftCMS
Client and Server-side React rendering
Laravel integration for blade-to-react
A simple, flexible Laravel package for adding polymorphic reactions to any model. React with any text: like, love, care, or anything you want.
统计信息
- 总下载量: 4.94k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 894
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-04-09