How to use the react-async.renderComponentToStringWithAsyncState function in react-async

To help you get started, we’ve selected a few react-async examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eiriklv / express-passport-app / helpers / react / render-markup-to-string.js View on Github external
exports = module.exports = function(options, callback) {
    var context = options.context || {};
    var callback = callback || function(err) {
        debug(err);
    };
    var clientScripts = options.clientScripts || [];
    var component = options.component || function() {
        debug('no component passed!');
    };

    // application data (this has the same effect as handlebars context, except for react components)
    var renderedComponent = component(context);

    // render the react markup to a string
    ReactAsync.renderComponentToStringWithAsyncState(renderedComponent, function(err, markup, data) {
        if (!markup) {
            debug(util.inspect(err));
            return callback('could not render markup - check server console');
        }

        // add doctype to markup (not possible in jsx - so it needs to be done dirty)
        markup = '' + markup;
        callback(err, options.staticPage ? markup : ReactAsync.injectIntoMarkup(markup, data, clientScripts));
    });
};
github htmlxprs / React-Isomorphic-Seed / app.js View on Github external
app.get('*',function(req,res){
        var path = url.parse(req.url).pathname;
        ReactAsync.renderComponentToStringWithAsyncState(App({path:path}),function(err, markup) {
            res.send(''+markup);
        });
    });
github jonykrause / isomorphic-blog-react / lib / renderRouteComponent.js View on Github external
function renderRouteComponent(req, res, next) {
  var path = url.parse(req.url).pathname;
  var app = ReactApp({path: path});
  ReactAsync.renderComponentToStringWithAsyncState(app, function(err, markup, data) {
    if (err) return next(err);
    res.send(ReactAsync.injectIntoMarkup(markup, data, ['/js/bundle.js']));
  });
}
github mindreframer / reactjs-stuff / github.com / jgebhardt / react-phonecat / server.js View on Github external
function renderApp(req, res, next) {
  var path = url.parse(req.url).pathname;
  var app = App({path: path});
  ReactAsync.renderComponentToStringWithAsyncState(app, function(err, markup) {
    if (err) {
      return next(err);
    }
    res.send(markup);
  });
}
github htmlxprs / React-Isomorphic-Seed / routes / index.js View on Github external
router.get('*',function(req,res){
   var path = url.parse(req.url).pathname;
   ReactAsync.renderComponentToStringWithAsyncState(App({path:path}),function(err, markup) {
        res.send(''+markup);
   });
});
github andreypopp / react-quickstart / server.js View on Github external
function renderApp(req, res, next) {
  var path = url.parse(req.url).pathname;
  var app = App({path: path});
  ReactAsync.renderComponentToStringWithAsyncState(app, function(err, markup) {
    if (err) {
      return next(err);
    }
    res.send('\n' + markup);
  });
}