I am trying to build an isomorphing app with Sails.js and React. Client-side part is easy. But I run into problems with server-side rendering.
When I try to server-render an *.jsx file with React, I got this:
renderToString(): You must pass a valid ReactElement
I am using sailsjs, react and sails-hook-babel (for ES6 syntax).
./assets/components/Auth.jsx:
import React from 'react';
export class Auth extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div className='auth'>
Very simple element without any logic just for test server-rendering.
</div>
);
}
}
./api/controllers/AuthController.js:
var Auth = require('./../../assets/components/Auth.jsx');
import React from 'react';
module.exports = {
render: function (req, res) {
//var markup = React.renderToString(
// Auth
//); // This throws an error
console.log(Auth); // {__esModule: true, Auth: [Function: Auth]}
//res.view("layout", {app: markup});
}
};
I have tried both ES5/ES6 syntax everywhere. Error occurs everytime. At clientside this Auth.jsx works fine (I am using webpack with babel-loader).