javascript - Node.js isomorphic-react-example error -
i saw https://github.com/davidwells/isomorphic-react-example , create simple one,but error message can't find module app,is miss something?or how should change code?thanks
server.js
var express = require('express'); var exphbs = require('express-handlebars'); var app = express(); require("node-jsx").install(); var react = require("react"); app = react.createfactory(require("app")); app.engine('handlebars', exphbs()); app.set('view engine', 'handlebars'); app.get('/', function (req, res) { var markup = react.rendertostring(app()); res.render('main', { title: 'express', markup: markup }); }); app.listen(3000);
app.js
var react = require("react"); var app = react.createclass({ getinitialstate() { return { search: "" }; }, render() { return ( <div classname="search-component"> <input type="text" onchange={this.changesearch} /> <p><span>you searching for: {this.state.search}</span></p> </div> ); }, changesearch(event) { var text = event.target.value; this.setstate({ search: text }); } }); module.exports = app;
main.handlebars
<!doycype html> <html> <head> <script> var = "as"; </script> <body> <p> main </p> {{{markup}}} </body> </html>
if want require file module have give pathname, in case ./app
if in same directory.
so line
app = react.createfactory(require("app"));
should become like
var app = react.createfactory(require("./app"));
Comments
Post a Comment