title: Node.js: How to serialize/deserialize a React component?
body: <p>I would like to serialize a React element (an instance of React component given props) and deserialize it elsewhere. Why you ask? I would like to be able to send the class from one process over stdout and render it in another process. I also want the rendered component to be interactive, so simply using <code>ReactDOM.renderToString()</code> will not suffice...</p>
  
  <p>What I've tried:</p>
  
  <ul>
  <li>Serializing it as a string and using <code>eval()</code> to deserialize it</li>
  <li>Using a custom replacer and reviver functions for <code>JSON.stringify()</code> and <code>JSON.parse()</code> respectively</li>
  </ul>
  
  <p><code>MyReactComponent.toString()</code> returns:</p>
  
  <pre><code>"function MyReactClass() {
      _classCallCheck(this, MyReactClass);
  
      _get(Object.getPrototypeOf(MyReactClass.prototype), 'constructor', this).apply(this, arguments);
  }"
  </code></pre>
  
  <p>which doesn't contain any of the methods unique to my component (such as <code>render()</code> or <code>constructor()</code>).</p>
  
  <p>See this example code in JS Bin: <a href="http://jsbin.com/febuzupicu/edit?js,console,output">http://jsbin.com/febuzupicu/edit?js,console,output</a></p>