65 // app.js import ReactDOM from 'react-dom'; import {ColorChooser} from './ColorChooser/ColorChooser'; $('div[data-color-chooser]').each((key, node) => { const input = $(node).find('input'); ReactDOM.render( color={input.val()} onColorChange={(color) => input.attr('value', color)} />, node ); }); Replacing the content of the node by the React tree
67 ✓ Allow to use great React components where it’s useful ✓ Do not add unnecessary complexity ✓ 100% compatible with Symfony Forms, HTTP, default browser behaviors, ...
70 ✓ HTML5 is scoped: data concerning a node is stored as attributes of the node ✓ HTML5 is semantic: many use cases are already considered in the standard ✓ HTML5 is flexible: you can add your own attributes
72 // app.js // ... $('div[data-color-chooser]').each((key, node) => { const input = $(node).find('input'); ReactDOM.render( type={node.getAttribute('data-color-chooser-type')} color={input.val()} onColorChange={(color) => input.attr('value', color)} />, node ); }); Using the option from the data attribute is easy because it’s scoped to the node
86 ✓ Same “no-refresh” effect as SPA ✓ Fully compatible with browser history, sessions, cache, … ✓ Better SEO (HTML rendered on the server) ✓ No added complexity over traditional Symfony apps