Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReactJS Server side rendering in Flask

I am just starting to learn ReactJS and am determining if its worth switching from AngularJS for use with Flask. I know one of the benefits of ReactJS is the way renderToString works to render and HTML string for faster load times and better SEO. From what I have read is the SEO is much better than what AngularJS can do although google is working to improve crawling Javascript.

My question is about how the SEO benefits would work with a Framework like Flask. Say I have a component like the one below and simply render it to my div. If I want to render this server side would I need to use something like nodejs or some Python library that can execute Javascript? If I try and do React.renderToString(.....) it doesn't do anything. If this is the case do the advertised benefits of SEO for ReactJS not really make it better than AngularJS? Please help me understand this and if its possible to render the Javascript Server Side with Flask about how may I go to achieve this?

var Foo = React.createClass({
    render: function() {
        return (
            <div>Foo</div>
        );
    }
});

React.render(<Foo  />, document.getElementById('foo'));
like image 664
mcd Avatar asked Jan 02 '15 20:01

mcd


Video Answer


1 Answers

This is for Django rather than Flask but should be easy to adapt the underlying technique: https://github.com/markfinger/django-react

like image 121
Andy Baker Avatar answered Oct 20 '22 03:10

Andy Baker