arryanggaputra / viewreact
Render a ReactJS component based on react-php-v8js
1.0.0
2017-10-15 16:14 UTC
Requires
- ext-v8js: >=0.1.3
This package is not auto-updated.
Last update: 2025-01-19 05:57:38 UTC
README
ViewReact is an php library that uses the power of Facebook's React library & React-PHP-V8Js to render UI components on the server-side with PHP as well as on the client.
Credits
Prerequisites
- Server running PHP 5.3.3+
- V8Js PHP extension
For a walkthrough how to setup V8Js PHP extension, use the links below:
Usage
- Prepare or create ReactJs Bundle Script
import React from 'react' import ReactDOM from 'react-dom'; import ReactDOMServer from 'react-dom/server'; import HelloWorldComponent from "./HelloWorldComponent"; window.React = React; window.ReactDOM = ReactDOM; window.ReactDOMServer = ReactDOMServer; window.HelloWorldComponent = HelloWorldComponent;
- Put ReactJs bundle script to
ViewReactSource
use Arryanggaputra\ViewReact; use Arryanggaputra\ViewReactSource; $reactSource = new ViewReactSource('/path/your/react/or/bundle/*.js'); $view = new ViewReact($reactSource); echo $view->render('HelloWorldComponent', [ 'name' => 'Jon', ]);
Result
<div data-reactid="11"><div data-reactid="12"><h1 data-reactid="13">Hello World <b>John</b></h1></div></div>