定制 tystr/react-js-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tystr/react-js-bundle

Composer 安装命令:

composer require tystr/react-js-bundle

包简介

A bundle for integrating reactjs into symfony. Provides server-side rendering via the v8js php extension for isomorphic apps.

README 文档

README

Build Status Code Climate Test Coverage

A bundle for integrating React into Symfony. Provides server-side rendering via the v8js PHP extension for building isomorphic applications.

Installation

Install tystr/react-js-bundle with composer:

# composer.phar require tystr/react-js-bundle:dev-master:~0.1

Configuration

Register the bundle with your application:

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Tystr\ReactJsBundle\TystrReactJsBundle(),
        // ...
    );
}

Configure the paths to your react.js and components javascript files:

# app/config.yml

tystr_react_js:
    react_path: path/to/react.js
    components_path: path/to/components.js

By default, the v8js PHP extension is used to render the react components. If you would prefer to use an external server to render the react components, you may configure an external rendering method:

# app/config.yml

tystr_react_js:
    react_path: path/to/react.js
    components_path: path/to/components.js
    render_method: external
    render_url: http://localhost:3000

This will cause a GET request to be made to the render_url value with the component and data ({name: Tyler} in this case) in the url as query parameters:

GET http://localhost:3000?component=MyComponent&data=%7B%22name%22%3A%22Tyler%22%7D

Usage

{{ react_component('MyComponent', 'my-component') }}

This will render the react component MyComponent on the server-side and place it inside a div with the id my-component.

To pass data to a component, pass a hash as the third argument:

{{ react_component('MyComponent', 'my-component', {'name': 'Tyler'}) }}

This makes this.props.name available in MyComponent.

To mount all components rendered server-side with the react_component function, use the react_mount_components twig function:

<script>
    {{ react_mount_components() }}
</script>

To mount a single react component (as long as it's already rendered with react_component), use the react_mount_component function:

<script>
    {{ react_mount_component('MyComponent') }}
</script>

Attempting to mount a component whose markup has not been rendered will result in an exception Tystr\ReactJsBundle\Exception\ComponentNotRenderedException.

统计信息

  • 总下载量: 13
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 13
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 13
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-12-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固