0.0.12 • Published 8 years ago

react-server-render v0.0.12

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

react-server-render

This package can render ReactJS components on server side returning the script to initialize the component on client side and the resulting component html. This task seems to be easy enough, so why a package?

// for this example i'll use a simple validation. You might need to check if window"varName" isset too. var initialState = ReactHandler.getInitialState("varName") !== null ? ReactHandler.getInitialState("varName") : window"varName"; // NOTE: Of course this initialState could be used to feed any Flux system, like Redux :)

var MyComponent = React.createClass({ getDefaultProps: function(){ return { text: null }; }, getInitialState: function(){ return initialState; }, render: function(){ return ( <div> {this.props.text} </div> ); } });

module.exports = MyComponent;

router.get('/', function(req, res, next) { var ComponentParsed = ReactHandler.getComponent( 'components/myComponent', {text: "Hello world"}, true, { componentId: "compId", state: ["varName", {todos:"1", "2", username: "danielmeneses"}] } );

res.render('index', {
    componentHtml: ComponentParsed.html,
    componentScript: ComponentParsed.script
});

}); ...

// js, jsx, ... (default: jsx) ReactHandler.REACT_FILES_EXTENSION = 'files_extension';

// production, developement, ... (default: process.env.NODE_ENV) ReactHandler.NODE_ENV = 'node_env';

About the getComponent() function:

0.0.12

8 years ago

0.0.11

8 years ago

0.0.10

8 years ago

0.0.9

8 years ago

0.0.8

8 years ago

0.0.7

8 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago