reactjs / react-php-v8js

PHP library that renders React components on the server
Other
1.33k stars 127 forks source link

Warnings #16

Open daslicht opened 9 years ago

daslicht commented 9 years ago

When I run the example I get the following warnings:

Warning: React.render is deprecated. Please use ReactDOM.render from require('react-dom') instead.warning @ react.js:18769
react.js:18769 Warning: render(): Target node has markup rendered by React, but there are unrelated nodes as well. This is most commonly caused by white-space inserted around server-rendered markup.warning @ react.js:18769
react.js:18769 Warning: Each child in an array or iterator should have a unique "key" prop. Check the top-level render call using <tr>. See https://fb.me/react-warning-keys for more information.warning @ react.js:18769
react.js:18769 Warning: Each child in an array or iterator should have a unique "key" prop. Check the top-level render call using <tbody>. See https://fb.me/react-warning-keys for more information.warning @ react.js:18769

How to fix ?

Finetuned commented 8 years ago

You can add react-dom into the code as follows: Caveat: this will not fix ReactDOMServer.renderToString in getMarkup()

Add react-dom.js to the parameters in example.php:

$rjs = new ReactJS(
file_get_contents('../../react/build/react.js'), // location of React's code
    file_get_contents('../../react/build/react-dom.js'), // location of React's code
    file_get_contents('../../react/build/table.js') // app code
);

Amend the constructor in ReactJS.php as follows:

 function __construct($libsrc, $libsrcDom, $appsrc)
    {
        $react = array();
        // stubs, react
        $react[] = "var console = {warn: function(){}, error: print}";
        $react[] = "var global = global || this, self = self || this, window = window || this";
        $react[] = $libsrc;
        $react[] = $libsrcDom;
        $react[] = "var React = global.React";
        $react[] = "var ReactDOM = global.ReactDOM";
        // app's components
        $react[] = $appsrc;
        $react[] = ';';

Replace React with ReactDOM in getJS()

 "ReactDOM.render(React.createElement(%s, %s), %s);",