Render ReactJS components in server side using reactjs/react-php-v8js
composer require qpautrat/reactjs-php-bundle
Whitelist following library in require section until maintainers release a version on packagist
"reactjs/react-php-v8js": "*@dev"
Register the bundle in your AppKernel
new QPautrat\ReactjsPhpBundle\ReactjsPhpBundle()
Add in your config.yml
file
reactjs_php:
library_path: path_to_reactjs_library
app_path: path_to_app_components
Use helper with php engine
<?php echo $view['reactjs']->renderMarkup('Component', array('foo' => 'bar')) ?>
<?php echo $view['reactjs']->renderJS('Component', '#dom_element', array('foo' => 'bar')) ?>
Or you can use our twig extension as well
{{ 'Component'|reactjs_render_markup({'foo':'bar'}) }}
{{ 'Component'|reactjs_render_js('#component', {'foo':'bar'}) }}
We provide a small demo application in another repository, living in a docker container, that you can use to test.
This bundle is available under the MIT License