Skip to content

Instantly share code, notes, and snippets.

@lukegb
Created January 15, 2016 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukegb/9609de88a2a09093b435 to your computer and use it in GitHub Desktop.
Save lukegb/9609de88a2a09093b435 to your computer and use it in GitHub Desktop.
Calling React from Python? Certainly!
import dukpy
ctx = dukpy.RequirableContext(['/homes/leg13/test/node_modules'])
ret = ctx.evaljs("""
var React = require('react');
var HelloWorld = React.createClass({
render: function() {
return React.createElement('p', null, 'Hi!');
}
});
({
React: React,
HelloWorld: HelloWorld
})
""")
React = ret.React
HelloWorld = ret.HelloWorld
print(React.renderToString(React.createElement(HelloWorld, None, '')))
@glittershark
Copy link

oh wow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment