All Projects → bTokman → yii2-react

bTokman / yii2-react

Licence: MIT License
Yii2 widget for server-side rendering ReactJs

Programming Languages

PHP
23972 projects - #3 most used programming language
javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to yii2-react

yii2-toastr
Yii2 - Javascript Toast Notifications
Stars: ✭ 25 (-34.21%)
Mutual labels:  yii2, yii2-widget
Yii2 Angular Boilerplate
Yii2 REST API + Angular10 Boilerplate (Frontend/Backend)
Stars: ✭ 194 (+410.53%)
Mutual labels:  yii2, server-side-rendering
angular-pwa
Angular 13 Example Progressive Web App (PWA)
Stars: ✭ 45 (+18.42%)
Mutual labels:  server-side-rendering
vue-ssr-starter
Starter kit for projects with Webpack 4, Vue 2 and SSR
Stars: ✭ 53 (+39.47%)
Mutual labels:  server-side-rendering
yii2-facades
Facades for Yii 2
Stars: ✭ 21 (-44.74%)
Mutual labels:  yii2
stimulus todomvc
[WIP] An implementation of TodoMVC using Ruby on Rails and StimulusJS
Stars: ✭ 14 (-63.16%)
Mutual labels:  server-side-rendering
yii2-websocket
基于swoole的websocket
Stars: ✭ 31 (-18.42%)
Mutual labels:  yii2
yii2-db
Database extensions for Yii 2.0 Framework 📦
Stars: ✭ 19 (-50%)
Mutual labels:  yii2
yii2-db-manager
Database Backup and Restore functionality
Stars: ✭ 96 (+152.63%)
Mutual labels:  yii2
server-authentication-next.js
No description or website provided.
Stars: ✭ 103 (+171.05%)
Mutual labels:  server-side-rendering
ng1-server
Node.js server side library for pre-rendering complex AngularJS app. Supports caching and URL rules.
Stars: ✭ 43 (+13.16%)
Mutual labels:  server-side-rendering
yii2-google-analytics
Google Analytics Universal tracking widget.
Stars: ✭ 14 (-63.16%)
Mutual labels:  yii2
yii2-star-rating
Star rating widget based on jQuery Raty
Stars: ✭ 16 (-57.89%)
Mutual labels:  yii2
yii2-time-down-counter
Widget for yii2, to start count down timer with a lot of options, This widget build dependence of timeDownCounter JS library
Stars: ✭ 15 (-60.53%)
Mutual labels:  yii2
ngext
Better routing for Angular
Stars: ✭ 78 (+105.26%)
Mutual labels:  server-side-rendering
yii2-logreader
Yii2 Log Reader
Stars: ✭ 31 (-18.42%)
Mutual labels:  yii2
awesome-yii2
Curated list of resources about using Yii2 - Yii is a high-performance component-based PHP framework.
Stars: ✭ 36 (-5.26%)
Mutual labels:  yii2
yii2-rest-doc
Yii2 REST doc generator
Stars: ✭ 35 (-7.89%)
Mutual labels:  yii2
SSR-React-Using-Serverless
SSR-React Using Serverless(aws)
Stars: ✭ 34 (-10.53%)
Mutual labels:  server-side-rendering
docker-php-yii2
🐳 💿 Docker PHP image containing extensions and libraries for Yii 2.0 Framework
Stars: ✭ 94 (+147.37%)
Mutual labels:  yii2

Yii2-React

This is Yii2 widget that able to use ReactJS components in your Yii2 app, with options of server-side rendering.

Installation

This widget require v8js php extesion. How to setup V8Js PHP extension? Use the links below:

Composer

Set the minimum-stability in your composer.json to dev 2. This widget compile react bundle from npm react and react-dom packages using browserify and uglify-js BUT since composer run scripts only for root composer.json, need to add the following lines to your composer.json:

... 
"scripts": {
"regenerate_react_bundle": [
   "vendor/b-tokman/yii2-react/build-bundles.sh"
],
"post-install-cmd":[
   "@regenerate_react_bundle",
],
"post-update-cmd": [
   "@regenerate_react_bundle",
]
...

This way composer will run browserify to create react-bundle.js and uglifyjs to minify it, each time after upgrade or install

  1. Then run
  $ composer require b-tokman/yii2-react

Composer will download yii2-react package with all dependenices, then npm will download react and react-dom npm packages and scripts will compile it.

Usage

After the installation you'll be able to use the bTokman\react\widgets\ReactRenderer widget in your app.

ReactRenderer::widget([
    'componentsSourceJs' => <pathToYourComponentJsFile>,
    'component' => <componentName>,
    'props' => [props],
    'options' => [options],
    'useTranspiler' => true //or false
])
  • componentsSourceJs - path to your react components js file
  • component - the name of global variable the contain your React component, you also can use namespased components by dot-notation
  • props - props array that'll be passed to your component
  • options - Array of options that you can pass to widget:
    • prerender - Tells widget to render your component server-side, by default - true
    • tag - The tag of the element where your component would be passed
    • html attributes - HTML attribute that will be added to the wrapper element of your component. Example: 'id' => 'root'.
  • useTranspiler - boolean, whatever to transpile js code, using bable or not. If you dont have JSX or other specific syntax, dont use transpiler, to save some time

All your reactJs components must be in window scope.

Example

In your view file:

echo ReactRenderer::widget([
    'componentsSourceJs' => 'js/main.js',
    'component' => 'Main',
    'props' => [ 'title' => 'Hello' ],
]);

Example main.js

class Main extends React.Component {
    render() {
        let title = this.props.title;
        return React.createElement(
            "main",
            null,
            React.createElement("div", null, title)
        );
    }
}
window.Main = Main;

Namespased components:

echo ReactRenderer::widget([
      'componentsSourceJs' => 'js/layout.js',
      'component' => 'Layout.Header',
      'props' => ['title' => 'Hello'],
]);

Example layout.js

class Header extends React.Component {
    render() {
        let title = this.props.title;
        return React.createElement(
            "header",
            null,
            React.createElement("div", null, title)
        );
    }
}
class Layout extends React.Component {
    render() {
        return React.createElement(
            "div",
            null,
            React.createElement(Layout.Header, {title: this.props.title})
        );
    }
}
Layout.Header = Header;
window.Header = Header;
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].