JSFiddle - React, Tailwind, and code Playground
HTML
<div id="content"><div data-reactroot=""><ul><li>Item 1</li><li>Item 2</li></ul><img/></div></div><script src="https://unpkg.com/react@16/umd/react.production.min.js"></script><script src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
JavaScript
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
var React = window.React,
DOM = require('react-dom-factories'),
div = DOM.div, ul = DOM.ul, li = DOM.li, img = DOM.img;
// This is just a simple example of a component that can be rendered on both
// the server and browser
class App extends React.Component {
render() {
return div(null,
ul({children: ["Item 1", "Item 2"].map(function(item) {
return li(null, item)
})}),
img(null)
)
}
};
module.exports = App;
},{"react-dom-factories":11}],2:[function(require,module,exports){
var React = window.React,
ReactDOM = window.ReactDOM,
// This is our React component, shared by server and browser thanks to browserify
App = React.createFactory(require('./App'))
// This script will run in the browser and will render our component using the
// value from APP_PROPS that we generate inline in the page's html on the server.
// If these props match what is used in the server render, React will see that
// it doesn't need to generate any DOM and the page will load faster
var parent = document.getElementById('content');
// add an item to the list
var newItem = document.createElement("li");
document.getElementsByTagName('ul')[0].appendChild(newItem);
newItem.innerText = "New Item";
// add a src and a click handler to the img
var img = document.getElementsByTagName('img')[0];
img.setAttribute('src', 'https://a1.nyt.com/assets/homepage/20170810-135137/images/foundation/logos/nyt-logo-379x64.png');
img.addEventListener('click', function() {
...