5

In node (using ejs) I can usually go:

res.render('home', {
        data: someData
});

is this still possible in react? I don't want to do client-side loading (via .ajax) for all my data, rather load some initial data and pass it to react (or flux). I haven't been able to find any examples of this.

James Montagne
  • 77,516
  • 14
  • 110
  • 130
Saad
  • 26,316
  • 15
  • 48
  • 69
  • 2
    React has server-side rendering: https://www.npmjs.com/package/react-server-example – tymeJV Mar 11 '15 at 19:01
  • http://facebook.github.io/react/docs/top-level-api.html#react.rendertostring for example. – WiredPrairie Mar 11 '15 at 19:56
  • are there any that use flux as well? – Saad Mar 11 '15 at 19:57
  • Yahoo have flux examples, dehydrating on the server, hydrating on the client. https://github.com/yahoo/flux-examples/blob/master/chat/server.js – Dean Burge Mar 11 '15 at 20:40
  • I made this React Isomoprhic Starterkit to showcase how to make the server and client work together elegantly to build an app. Check it out, it passes "context data" from Node to the browser. https://github.com/RickWong/react-isomorphic-starterkit –  Mar 12 '15 at 23:14
  • Does this answer your question? [Passing an object to client in node/express + ejs?](https://stackoverflow.com/questions/11151632/passing-an-object-to-client-in-node-express-ejs) – Javid Jamae Jun 16 '20 at 01:15

1 Answers1

-1
  1. If using redux you could have some initial data in your reducers as default values.
  2. If not using redux you can have default data in defaultProps for each component.
  3. If you need to fetch your default/initial data you could emit an action in componentDidMount.
locropulenton
  • 4,743
  • 3
  • 32
  • 57